Skip to content

gh-149816: Fix a race condition in _PyBytes_FromList with free-threading#149909

Merged
sobolevn merged 1 commit into
python:mainfrom
sobolevn:issue-149816-128
May 16, 2026
Merged

gh-149816: Fix a race condition in _PyBytes_FromList with free-threading#149909
sobolevn merged 1 commit into
python:mainfrom
sobolevn:issue-149816-128

Conversation

@sobolevn
Copy link
Copy Markdown
Member

@sobolevn sobolevn commented May 16, 2026

_PyBytes_FromList is called from PyBytes_FromObject which does not own the passed object, so it is a borrowed reference.

Using _PyList_GetItemRef seems like the correct solution here.
However, I was not successful in actually triggering the failure without C-API direct usage.

Copy link
Copy Markdown
Contributor

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

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

LGTM

@sobolevn sobolevn added needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels May 16, 2026
@sobolevn sobolevn enabled auto-merge (squash) May 16, 2026 08:15
@sobolevn sobolevn merged commit 46afba7 into python:main May 16, 2026
65 checks passed
@miss-islington-app
Copy link
Copy Markdown

Thanks @sobolevn for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app
Copy link
Copy Markdown

Sorry, @sobolevn, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 46afba7b9324bc9492c3527d0fe47dd74f1f598c 3.14

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 16, 2026

GH-149911 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 16, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 16, 2026

GH-149912 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label May 16, 2026
@eendebakpt
Copy link
Copy Markdown
Contributor

@sobolevn @kumaraditya303 The same issue was addressed in #132590, which takes a different approach. Using Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST we can unify the tuple and list cases and improve performance. It also adds a FT test. Could you have a look at that PR please?

sobolevn added a commit that referenced this pull request May 16, 2026
…ee-threading (GH-149909) (#149911)

gh-149816: Fix a race condition in `_PyBytes_FromList` with free-threading (GH-149909)
(cherry picked from commit 46afba7)

Co-authored-by: sobolevn <mail@sobolevn.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants