{"action":"created","issue":{"url":"https://api.github.com/repos/pyca/pyopenssl/issues/520","repository_url":"https://api.github.com/repos/pyca/pyopenssl","labels_url":"https://api.github.com/repos/pyca/pyopenssl/issues/520/labels{/name}","comments_url":"https://api.github.com/repos/pyca/pyopenssl/issues/520/comments","events_url":"https://api.github.com/repos/pyca/pyopenssl/issues/520/events","html_url":"https://github.com/pyca/pyopenssl/issues/520","id":173888068,"number":520,"title":"Regression: M2Crypto.m2.rand_bytes() hangs on Apache+mod_wsgi with pyOpenSSL 16.1.10","user":{"login":"porridge","id":489420,"avatar_url":"https://avatars.githubusercontent.com/u/489420?v=3","gravatar_id":"","url":"https://api.github.com/users/porridge","html_url":"https://github.com/porridge","followers_url":"https://api.github.com/users/porridge/followers","following_url":"https://api.github.com/users/porridge/following{/other_user}","gists_url":"https://api.github.com/users/porridge/gists{/gist_id}","starred_url":"https://api.github.com/users/porridge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/porridge/subscriptions","organizations_url":"https://api.github.com/users/porridge/orgs","repos_url":"https://api.github.com/users/porridge/repos","events_url":"https://api.github.com/users/porridge/events{/privacy}","received_events_url":"https://api.github.com/users/porridge/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-29T22:28:15Z","updated_at":"2016-08-30T10:19:34Z","closed_at":null,"body":"\r\nSince upgrading:\r\n  * cryptography (1.4) -> (1.5)\r\n  * pyOpenSSL (16.0.0) -> (16.1.0)\r\n\r\nmy web app reliably hangs, in a simple ``M2Crypto.m2.rand_bytes(16)`` call.\r\nAt the same time entropy_avail hovers around 800, and calling the function from a standalone python interperter works just fine. Apparently the issue is only when running inside Apache.\r\n\r\nDowngrading cryptography alone (to 1.4) does not help. But downgrading pyOpenSSL (to 16.0.0) as well, makes it work again. I did not try downgrading pyOpenSSL alone.\r\n\r\nI suspect this is something along the lines of https://github.com/pyca/cryptography/issues/2299, but I don't pretend to understand the details.\r\n\r\nExample stack trace of a hanging request thread:\r\n\r\n```\r\nThread 14 (Thread 0x7f5f0cb9b700 (LWP 88)):\r\n#0  sem_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:85\r\n#1  0x00007f5f0ea5b6d8 in PyThread_acquire_lock (\r\n    lock=lock@entry=0x7f5f1450f9e0, waitflag=waitflag@entry=1)\r\n    at ../Python/thread_pthread.h:324\r\n#2  0x00007f5f0ea80386 in PyEval_RestoreThread (\r\n    tstate=tstate@entry=0x7f5ef8bbc620) at ../Python/ceval.c:357\r\n#3  0x00007f5f0ea807c8 in PyGILState_Ensure () at ../Python/pystate.c:611\r\n#4  0x00007f5effa44fbd in gil_ensure () at c/misc_thread_common.h:113\r\n#5  0x00007f5effa4a001 in cffi_call_python (\r\n    externpy=0x7f5efff3f0a0 <_cffi_externpy__Cryptography_rand_bytes>, \r\n    args=0x7f5f0cb99f70 \"\\220S\\270\\370^\\177\") at c/call_python.c:234\r\n#6  0x00007f5effc9843c in Cryptography_rand_bytes (a0=<optimized out>, \r\n    a1=<optimized out>) at build/temp.linux-x86_64-2.7/_openssl.c:11769\r\n#7  0x00007f5efccdc223 in rand_bytes ()\r\n   from /usr/lib/python2.7/dist-packages/M2Crypto/__m2crypto.so\r\n#8  0x00007f5efccdc2c6 in ?? ()\r\n   from /usr/lib/python2.7/dist-packages/M2Crypto/__m2crypto.so\r\n#9  0x00007f5f0ea6f0d4 in call_function (oparg=<optimized out>, \r\n    pp_stack=0x7f5f0cb9a110) at ../Python/ceval.c:4020\r\n#10 PyEval_EvalFrameEx (f=f@entry=0x7f5ef8089f00, throwflag=throwflag@entry=0)\r\n    at ../Python/ceval.c:2666\r\n#11 0x00007f5f0ea6f059 in fast_function (nk=<optimized out>, na=3, n=3, \r\n    pp_stack=0x7f5f0cb9a290, func=0x7f5efcbf6b18) at ../Python/ceval.c:4106\r\n#12 call_function (oparg=<optimized out>, pp_stack=0x7f5f0cb9a290)\r\n    at ../Python/ceval.c:4041\r\n#13 PyEval_EvalFrameEx (f=f@entry=0x7f5efea89050, throwflag=throwflag@entry=0)\r\n    at ../Python/ceval.c:2666\r\n#14 0x00007f5f0ea6f059 in fast_function (nk=<optimized out>, na=2, n=2, \r\n    pp_stack=0x7f5f0cb9a410, func=0x7f5f05934758) at ../Python/ceval.c:4106\r\n#15 call_function (oparg=<optimized out>, pp_stack=0x7f5f0cb9a410)\r\n    at ../Python/ceval.c:4041\r\n#16 PyEval_EvalFrameEx (f=f@entry=0x7f5efcbf8b60, throwflag=throwflag@entry=0)\r\n    at ../Python/ceval.c:2666\r\n#17 0x00007f5f0ea7054d in PyEval_EvalCodeEx (co=<optimized out>, \r\n    globals=<optimized out>, locals=locals@entry=0x0, args=<optimized out>, \r\n    argcount=argcount@entry=1, kws=0x7f5ef8ca9af8, kwcount=0, defs=0x0, \r\n    defcount=0, closure=closure@entry=0x0) at ../Python/ceval.c:3252\r\n#18 0x00007f5f0ea6edd8 in fast_function (nk=<optimized out>, na=1, n=1, \r\n    pp_stack=0x7f5f0cb9a630, func=0x7f5f0592b9b0) at ../Python/ceval.c:4116\r\n#19 call_function (oparg=<optimized out>, pp_stack=0x7f5f0cb9a630)\r\n    at ../Python/ceval.c:4041\r\n#20 PyEval_EvalFrameEx (f=f@entry=0x7f5ef8ca9940, throwflag=throwflag@entry=0)\r\n    at ../Python/ceval.c:2666\r\n#21 0x00007f5f0ea6f059 in fast_function (nk=<optimized out>, na=3, n=3, \r\n    pp_stack=0x7f5f0cb9a7b0, func=0x7f5f05939758) at ../Python/ceval.c:4106\r\n#22 call_function (oparg=<optimized out>, pp_stack=0x7f5f0cb9a7b0)\r\n    at ../Python/ceval.c:4041\r\n#23 PyEval_EvalFrameEx (f=f@entry=0x7f5ef8c92240, throwflag=throwflag@entry=0)\r\n    at ../Python/ceval.c:2666\r\n#24 0x00007f5f0ea7054d in PyEval_EvalCodeEx (co=<optimized out>, \r\n    globals=<optimized out>, locals=locals@entry=0x0, \r\n    args=args@entry=0x7f5f13acbc98, argcount=3, kws=kws@entry=0x0, \r\n    kwcount=kwcount@entry=0, defs=defs@entry=0x0, defcount=defcount@entry=0, \r\n    closure=0x0) at ../Python/ceval.c:3252\r\n#25 0x00007f5f0eaa56d0 in function_call (func=0x7f5f05939848, \r\n    arg=0x7f5f13acbc80, kw=0x0) at ../Objects/funcobject.c:526\r\n#26 0x00007f5f0ea11d43 in PyObject_Call (func=func@entry=0x7f5f05939848, \r\n    arg=arg@entry=0x7f5f13acbc80, kw=kw@entry=0x0)\r\n    at ../Objects/abstract.c:2529\r\n#27 0x00007f5f0e99d7bd in instancemethod_call.8988 (func=0x7f5f05939848, \r\n    arg=0x7f5f13acbc80, kw=0x0) at ../Objects/classobject.c:2602\r\n#28 0x00007f5f0ea11d43 in PyObject_Call (func=func@entry=0x7f5efeb238c0, \r\n    arg=arg@entry=0x7f5efcbae4d0, kw=kw@entry=0x0)\r\n    at ../Objects/abstract.c:2529\r\n#29 0x00007f5f0ea167e5 in slot_tp_call.26779 (self=<optimized out>, \r\n    args=0x7f5efcbae4d0, kwds=0x0) at ../Objects/typeobject.c:5432\r\n#30 0x00007f5f0ea11d43 in PyObject_Call (func=func@entry=0x7f5efcc3fb10, \r\n    arg=arg@entry=0x7f5efcbae4d0, kw=<optimized out>)\r\n    at ../Objects/abstract.c:2529\r\n#31 0x00007f5f0ea8a577 in PyEval_CallObjectWithKeywords (func=0x7f5efcc3fb10, \r\n    arg=0x7f5efcbae4d0, kw=<optimized out>) at ../Python/ceval.c:3889\r\n#32 0x00007f5f0ee5d644 in ?? () from /usr/lib/apache2/modules/mod_wsgi.so\r\n#33 0x00007f5f0ee63ba8 in ?? () from /usr/lib/apache2/modules/mod_wsgi.so\r\n#34 0x00007f5f131b3184 in start_thread (arg=0x7f5f0cb9b700)\r\n    at pthread_create.c:312\r\n#35 0x00007f5f12ee037d in clone ()\r\n    at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111\r\n```"},"comment":{"url":"https://api.github.com/repos/pyca/pyopenssl/issues/comments/243396744","html_url":"https://github.com/pyca/pyopenssl/issues/520#issuecomment-243396744","issue_url":"https://api.github.com/repos/pyca/pyopenssl/issues/520","id":243396744,"user":{"login":"reaperhulk","id":161495,"avatar_url":"https://avatars.githubusercontent.com/u/161495?v=3","gravatar_id":"","url":"https://api.github.com/users/reaperhulk","html_url":"https://github.com/reaperhulk","followers_url":"https://api.github.com/users/reaperhulk/followers","following_url":"https://api.github.com/users/reaperhulk/following{/other_user}","gists_url":"https://api.github.com/users/reaperhulk/gists{/gist_id}","starred_url":"https://api.github.com/users/reaperhulk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reaperhulk/subscriptions","organizations_url":"https://api.github.com/users/reaperhulk/orgs","repos_url":"https://api.github.com/users/reaperhulk/repos","events_url":"https://api.github.com/users/reaperhulk/events{/privacy}","received_events_url":"https://api.github.com/users/reaperhulk/received_events","type":"User","site_admin":false},"created_at":"2016-08-30T10:19:34Z","updated_at":"2016-08-30T10:19:34Z","body":"Does this problem go away if you do:\r\n\r\n```\r\nfrom cryptography.hazmat.backends.openssl.backed import backend\r\nbackend.activate_builtin_random()\r\n```\r\n\r\nright after importing pyopenssl?"}}
{"actor":{"display_login":"reaperhulk"}}