GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-152741: Publish thread states to the interpreter's thread list only after they are fully initialized by kumaraditya303 · Pull Request #156202 · python/cpython

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Aug 21, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Issue: Data race between sys._current_exceptions() and a concurrently attaching thread #152741

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kumaraditya303
pythongh-152741: Publish thread states to the interpreter's thread li…
6213ab4
…st only after they are fully initialized
@bedevere-app bedevere-app Bot mentioned this pull request Aug 21, 2026
Data race between sys._current_exceptions() and a concurrently attaching thread #152741
Open
@kumaraditya303 kumaraditya303 added the skip news label Aug 21, 2026
@kumaraditya303
fix eval breaker version
5d1fcf7
@kumaraditya303
kumaraditya303 marked this pull request as ready for review August 22, 2026 07:50
@kumaraditya303
kumaraditya303 requested review from FFY00, ZeroIntensity and ericsnowcurrently as code owners August 22, 2026 07:50
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 22, 2026
@kumaraditya303
kumaraditya303 requested a review from mpage September 9, 2026 16:11
@kumaraditya303
Merge branch 'main' into pythongh-152741-defer-tstate-publish
ea15c1d
@kumaraditya303 kumaraditya303 added the topic-free-threading label Sep 9, 2026
@ambv ambv mentioned this pull request Oct 20, 2026
gh-152741: Fix data race on PyThreadState.thread_id during thread bind #152755
Closed
@kumaraditya303
Merge remote-tracking branch 'upstream/main' into pythongh-152741-def…
5ba1e0f
…er-tstate-publish

# Conflicts:
#	Python/pystate.c
mpage
mpage requested changes Nov 11, 2026
View reviewed changes
Comment thread Python/pystate.c
Comment on lines -1718 to -1720
// Add the new thread state to the interpreter.
PyThreadState *old_head = interp->threads.head;
add_threadstate(interp, (PyThreadState *)tstate, old_head);

@mpage mpage Nov 11, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Codex flagged that moving add_threadstate() into bind_tstate() introduces a potential use after free caused by a race with interpreter shutdown. I think it's right. Here's the race:

  1. A new daemon thread, D, is started, but something causes a delay between thread creation and when it's bound.
  2. Another thread finalizes the interpreter, but because D's thread state hasn't been inserted into the thread list, finalization doesn't see it and doesn't set its state to _Py_THREAD_SHUTTING_DOWN.
  3. D resumes. Its state is still _Py_THREAD_DETACHED so it continues normal execution and attempts to dereference tstate->interp. This results in either interacting with a finalized interpreter (the main interpreter) or freed memory (a subinterpreter).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting core review labels Nov 11, 2026
@bedevere-app

bedevere-app Bot commented Nov 11, 2026

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@mpage mpage mpage requested changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity ZeroIntensity is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting changes skip news topic-free-threading

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@kumaraditya303 @mpage
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.