Created
December 24, 2013 15:00
-
-
Save public/8114440 to your computer and use it in GitHub Desktop.
Crashes quickly on my Ubuntu machine when _ssl is not imported and there at least 3 threads. Reducing threads or importing _ssl seems to work around the race. _ssl happens to setup locking callbacks OpenSSL wants to do multi-threading safely. I think this will still crash if we import a different OpenSSL to the one the Python implementation is l…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import thread | |
| import threading | |
| import struct | |
| import itertools | |
| import cryptography.hazmat.backends | |
| # UNCOMMENT THIS TO POSSIBLY STOP CRASHES | |
| #import _ssl | |
| def randloop(): | |
| s = b.ffi.new("char[]", 16) | |
| sb = b.ffi.buffer(s) | |
| sb[:] = b"\0" * 16 | |
| for i in itertools.count(): | |
| b.lib.RAND_seed(s, 16) | |
| if i % 10000 == 0: | |
| print thread.get_ident(), i | |
| b = cryptography.hazmat.backends.default_backend() | |
| threads = [] | |
| print "Starting..." | |
| for x in range(3): | |
| t = threading.Thread(target=randloop) | |
| t.daemon = True | |
| t.start() | |
| threads.append(t) | |
| print "Waiting..." | |
| while threads: | |
| for t in threads: | |
| t.join(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment