Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-134698: Hold a lock when the thread state is detached inssl#134724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ZeroIntensity wants to merge8 commits intopython:main
base:main
Choose a base branch
Loading
fromZeroIntensity:fix-ssl-race

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensityZeroIntensity commentedMay 26, 2025
edited by bedevere-appbot
Loading

Inside ofPy_BEGIN_ALLOW_THREADS blocks, OpenSSL calls need to be synchronized to prevent crashes. I'm doing this with a per-object mutex that is only held inside when the GIL or critical section is released.

@ZeroIntensity
Copy link
MemberAuthor

@Conobi Would you mind pointing me to the downstream FastAPI issue?

@Conobi
Copy link

Conobi commentedMay 26, 2025
edited
Loading

@ZeroIntensity
Copy link
MemberAuthor

FastAPI was having problems with this in their test suite, right? Is there someone I should CC?


/* Make sure the SSL error state is initialized */
ERR_clear_error();

PySSL_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

UsePySSL_BEGIN_ALLOW_THREADS(ssl->ctx) here. The PySSLContext's ctx is being accessed by SSL_new so we should lock it.

ZeroIntensity and emmatyping reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Would probably be good to add a test creating ssl contexts in multiple threads as well.

Copy link
MemberAuthor

@ZeroIntensityZeroIntensityMay 26, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

There's nothing too special about this function, though. I'm not sure it's worth the effort to add a test for every single function fixed here.

emmatyping reacted with thumbs up emoji
Copy link
Member

@emmatypingemmatyping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Great to see the improved thread safety! 🚀

self->ssl = SSL_new(ctx);
PySSL_END_ALLOW_THREADS
PySSL_END_ALLOW_THREADS(sslctx)
_PySSL_FIX_ERRNO;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This one shouldn't be needed, or am I wrong?

emmatyping and ZeroIntensity reacted with thumbs up emoji
BIO_free_all(bio);
PySSL_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You're missing a call to_PySSL_FIX_ERRNO here

ZeroIntensity reacted with thumbs up emoji
Copy link
Contributor

@kumaraditya303kumaraditya303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

See the discussion on issue, I am not convinced that adding more locks is the solution, it will degrade performance in multi threaded "safe" workloads which work today.

ZeroIntensity reacted with thumbs up emoji
@bedevere-app
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ZeroIntensity
Copy link
MemberAuthor

See the discussion on issue, I am not convinced that adding more locks is the solution, it will degrade performance in multi threaded "safe" workloads which work today.

Wait a minute, there shouldn't be any multithreaded workloads that get hit by this, right? They'll all crash right now.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gpsheadgpsheadgpshead left review comments

@picnixzpicnixzpicnixz left review comments

@kumaraditya303kumaraditya303kumaraditya303 requested changes

@emmatypingemmatypingemmatyping approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@ZeroIntensity@Conobi@gpshead@emmatyping@picnixz@kumaraditya303

[8]ページ先頭

©2009-2025 Movatter.jp