From: Jean-Paul C. <ex...@di...> - 2009-04-01 22:56:43
|
On Wed, 1 Apr 2009 15:26:43 -0500, Jean-Paul Calderone <ex...@di...> wrote: > > [snip] > >I wasn't actually very confident that the patch was correct, but now that >I've actually written all that up and traced through the various levels of >thread control APIs in CPython, I'm relatively confident that the patch is >doing the right thing. I also learned that there are some APIs in CPython >which do much of what pyOpenSSL is doing. They aren't available in Python >2.3 though, so I'm not quite ready to switch over to them. Shortly after sending this message, I realized that it is also a perfectly valid explanation for why the current trunk code also works correctly and does not segfault. However, the current trunk code does segfault, so something must be wrong. ;) After a few hours with gdb, I found the problem. Python threads identifiers are only unique for the lifetime of the thread. As threads are destroyed and others created, the identifiers may be re-used. Since thread identifiers are used as TLS keys, this means that thread A may set a TLS key then exit and a later thread B may then be able to see the value for that TLS key. This means that without the delete, thread B won't save the correct new PyThreadState*, thus causing the bug. Jean-Paul |