Wrap JSContext() with JSLocker() lock#42
Conversation
Make PyV8.JSContext thread safe by wrapping it in a lock. Multithreaded programs that call peepdf may cause peepdf analyses to mysteriously segfault without this. This is an issue with PyV8 in general. Examples of other people having similar issues with PyV8 in multithreaded applications: http://inarticulateloquence.com/django-pyv8/ http://www.pythoneye.com/440_11816513/ Copied from my earlier defunct PR at viper-framework/viper#130.
|
Hi! Thanks for the pull request ;) I have tested it and I get the following error in line 101: File "build/bdist.linux-x86_64/egg/PyV8.py", line 176, in exit The PR is also based in a previous peepdf commit, but not a big issue there... |
|
I changed it to leave the context before releasing the lock. I notice the context object is returned at https://github.com/ianshefferman/peepdf/blob/patch-1/JSAnalysis.py#L139, but I don't think that should affect functionality. |
|
Well, really it affects ;) This is because the context is stored globally, so when we try to check the variables existent in the context (js_vars) it fails. Traceback (most recent call last): Isn't there a way to release the lock without leaving the context? |
Make PyV8.JSContext instance thread safe by wrapping it in a lock. Multithreaded programs that call peepdf may cause peepdf analyses to mysteriously segfault without this lock. This is an issue with PyV8 in general.
Examples of other people having similar issues with PyV8 in multithreaded applications:
http://inarticulateloquence.com/django-pyv8/
http://www.pythoneye.com/440_11816513/
Those links both appear to be dead now, unfortunately, but adding this lock resolved a segfault I was observing, which I suspected was being caused by a race condition.
Copied from my earlier defunct PR at viper-framework/viper#130.