Uh oh!
There was an error while loading. Please reload this page.
gh-124984: Fix ssl thread safety - #124993
Conversation
Uh oh!
There was an error while loading. Please reload this page.
JelleZijlstra
left a comment
There was a problem hiding this comment.
Thanks, that's a lot of locks.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
vstinner
commented
Oct 19, 2024
Remaining question: should we backport this enhancement (bugfix?) to Python 3.13? |
ZeroIntensity
commented
Oct 19, 2024
Yeah, I had the same thought. I'll leave that decision to @Yhg1s |
Yhg1s
commented
Oct 20, 2024
vstinner
commented
Oct 20, 2024
Without this change, the |
I think that fixing the SSL module crash in the 3.13 free threading build is important -- lots of basic tasks around HTTP requests are likely to crash without it. I don't think "lines of code changed" is a good measure of the complexity here -- the If backporting this PR is a nonstarter than we should consider a smaller, more targeted change that only adds |
Also, thank you @ZeroIntensity for fixing this bug and @vstinner, @corona10, and everyone else that reviewed the PR. |
Thanks @ZeroIntensity for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, @ZeroIntensity and @vstinner, I could not cleanly backport this to |
vstinner
commented
Oct 21, 2024
@ZeroIntensity: Automated backport failed. Would you mind to backport the change manually? With a backport, it might be easier to take a decision on fixing 3.13 or not. |
ZeroIntensity
commented
Oct 21, 2024
Yeah, I can do it later today. |
GH-125780 is a backport of this pull request to the 3.13 branch. |
Make SSL objects thread safe in Free Theaded build by using critical sections. (cherry picked from commit 4c53b25) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
vstinner
commented
Oct 29, 2024
@Yhg1s: Are you still against the backport to 3.13 after @colesbury's comment? |
Yhg1s
commented
Nov 4, 2024
I'm okay with a backport of just the @critical_section changes (since those expand to nothing in the normal build, and the free-threaded build is experimental anyway). It's the larger refactorings that worry me. |
vstinner
commented
Nov 4, 2024
Other changes are tests and changes to use the code declared with |
ZeroIntensity
commented
Nov 4, 2024
There isn't any other refactoring going on here, I just had to switch the getters and setters over to AC for the critical section. Another issue is that not backporting this to 3.13 will also hurt any automatic backports for |
Make SSL objects thread safe in Free Theaded build by using critical sections. (cherry picked from commit 4c53b25) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Make SSL objects thread safe in Free Theaded build by using critical sections. Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
| #endif | ||
| #if defined(_SSL__SSLCONTEXT_SECURITY_LEVEL_GETSETDEF) | ||
| # undef _SSL__SSLCONTEXT_SECURITY_LEVEL_GETSETDEF | ||
| # define _SSL__SSLCONTEXT_SECURITY_LEVEL_GETSETDEF {"security_level", (getter)_ssl__SSLContext_security_level_get, (setter)_ssl__SSLContext_security_level_set, _ssl__SSLContext_security_level_DOCSTR}, |
There was a problem hiding this comment.
The symbol _ssl__SSLContext_security_level_set is used here, but nowhere added
There was a problem hiding this comment.
This is generated clinic code. I'm pretty sure this route is never taken, and the macro right after this is used instead.
There was a problem hiding this comment.
Oh, thank you. I didn't know that

As it turns out, OpenSSL doesn't like being called in multiple threads. This adds a per-socket (and per-context and per-session) lock for all OpenSSL calls.
requests#124984