Skip to content

Instantly share code, notes, and snippets.

@public
Created December 24, 2013 15:00
Show Gist options
  • Select an option

  • Save public/8114440 to your computer and use it in GitHub Desktop.

Select an option

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…
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