Skip to content

gh-144766: Fix a crash in fork child process when perf support is enabled.#144795

Merged
pablogsal merged 2 commits intopython:mainfrom
yilei:yilei-fix-trampoline-crash
Feb 14, 2026
Merged

gh-144766: Fix a crash in fork child process when perf support is enabled.#144795
pablogsal merged 2 commits intopython:mainfrom
yilei:yilei-fix-trampoline-crash

Conversation

@yilei
Copy link
Contributor

@yilei yilei commented Feb 13, 2026

Why? After fork, _PyPerfTrampoline_Fini may leave the old code watcher registered if trampolined code objects from the parent still exist (trampoline_refcount > 0).

This change clears it unconditionally before _PyPerfTrampoline_Init registers a new one, to prevent two watchers sharing the same globals and double-decrementing trampoline_refcount.

Also added test_trampoline_works_after_fork_with_many_code_objects, and verified it fails before the fix.

@yilei
Copy link
Contributor Author

yilei commented Feb 13, 2026

The macOS free-threading test failures seem unrelated.

@gpshead gpshead self-assigned this Feb 13, 2026
Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

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

This makes sense to me! Thanks for taking the time to produce a good test for this and the excellent investigation and the fix ❤️

@pablogsal pablogsal added needs backport to 3.14 bugs and security fixes needs backport to 3.13 bugs and security fixes labels Feb 14, 2026
@pablogsal pablogsal merged commit 5922149 into python:main Feb 14, 2026
93 of 95 checks passed
@miss-islington-app
Copy link

Thanks @yilei for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 14, 2026
…is enabled. (pythonGH-144795)

(cherry picked from commit 5922149)

Co-authored-by: Yilei <hi@mangoumbrella.com>
@miss-islington-app
Copy link

Sorry, @yilei and @pablogsal, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 5922149a5033ec1151320864e605adf88f53f280 3.13

@miss-islington-app miss-islington-app bot assigned pablogsal and unassigned gpshead Feb 14, 2026
@bedevere-app
Copy link

bedevere-app bot commented Feb 14, 2026

GH-144816 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 Feb 14, 2026
@pablogsal
Copy link
Member

@yilei can you try to follow the instructions to do the 3.13 backport by hand? Otherwise I can do it later today so no worries :)

pablogsal pushed a commit that referenced this pull request Feb 14, 2026
pablogsal pushed a commit to pablogsal/cpython that referenced this pull request Feb 14, 2026
…upport is enabled. (pythonGH-144795)

(cherry picked from commit 5922149)

Co-authored-by: Yilei <hi@mangoumbrella.com>
@bedevere-app
Copy link

bedevere-app bot commented Feb 14, 2026

GH-144818 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Feb 14, 2026
@yilei
Copy link
Contributor Author

yilei commented Feb 14, 2026

@yilei can you try to follow the instructions to do the 3.13 backport by hand? Otherwise I can do it later today so no worries :)

I can get to it ~Monday if you haven't done so then.

pablogsal added a commit that referenced this pull request Feb 14, 2026
… is enabled. (GH-144795) (#144818)

(cherry picked from commit 5922149)

Co-authored-by: Yilei <hi@mangoumbrella.com>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Arch Linux Usan Function 3.13 (no tier) has failed when building commit 0151abc.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1601/builds/656) and take a look at the build logs.
  4. Check if the failure is related to this commit (0151abc) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1601/builds/656

Failed tests:

  • test_urllib2net

Summary of the results of the build (if available):

==

Click to see traceback logs
Note: switching to '0151abcd9f580f9460269f9787af7ad883c8362b'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 0151abcd9f5 [3.13] gh-144766: Fix a crash in fork child process when perf support is enabled. (GH-144795) (#144818)
Switched to and reset branch '3.13'

make: *** [Makefile:2252: buildbottest] Error 2

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.

4 participants