Skip to content

gh-151524: Avoid using instrumentation callback result after Py_DECREF - #151525

Merged
ZeroIntensity merged 3 commits into
python:mainfrom
lpyu001:fix-use-after-Py_DECREF-comparison2
Aug 7, 2026
Merged

gh-151524: Avoid using instrumentation callback result after Py_DECREF#151525
ZeroIntensity merged 3 commits into
python:mainfrom
lpyu001:fix-use-after-Py_DECREF-comparison2

Conversation

@lpyu001

@lpyu001lpyu001 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@chris-eiblchris-eibl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The change lgtm, but I'd create a news entry, like almost all of the fixes for the umbrella issue #146102 did so far.

cc @pablogsal

@bedevere-app

Copy link
Copy Markdown

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 phrase I 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.

@lpyu001

Copy link
Copy Markdown
ContributorAuthor

The change lgtm, but I'd create a news entry, like almost all of the fixes for the umbrella issue #146102 did so far.

cc @pablogsal

I’ve submitted the news entry.thanks

@sobolevnsobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: was it ever tested? Or was just the RC of res higher than 1, so no crash happened?

@@ -0,0 +1,2 @@
Avoid comparing the result of a ``sys.monitoring`` callback after

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would be a user-facing news entry. Users care about crashes (which could happen here), not about RC :)
Let's rephrase it.

@ZeroIntensityZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This isn't UB. _PyInstrumentation_DISABLE is an immortal object; Py_DECREF operations on it are a no-op.

>>> import sys
>>> sys._is_immortal(sys.monitoring.DISABLE)
True

That said, I do agree that it's misleading. Let's either remove the Py_DECREF call entirely and/or add an assertion that it's immortal.

@bedevere-app

Copy link
Copy Markdown

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 phrase I 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.

@aisk

aisk commented Jul 21, 2026

Copy link
Copy Markdown
Member

Hi @lpyu001 I see you made some update on this PR, and currently I think it look fine. Can you reply "I have made the requested changes; please review again" in the comments as the bot said, to require other reviewers continue the work?

@lpyu001

Copy link
Copy Markdown
ContributorAuthor

I have made the requested changes; please review again

@bedevere-app

Copy link
Copy Markdown

Thanks for making the requested changes!

@chris-eibl, @ZeroIntensity: please review the changes made to this pull request.

@chris-eiblchris-eibl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lgtm and helps me who didn't realize _PyInstrumentation_DISABLE is immortal 👍

@lpyu001

Copy link
Copy Markdown
ContributorAuthor

The PR has been mergeable for two weeks. Could we go ahead and merge it? @ZeroIntensity@chris-eibl

aisk
aisk approved these changes Aug 7, 2026
@ZeroIntensity
ZeroIntensity merged commit 52bed26 into python:mainAug 7, 2026
56 of 59 checks passed
@ZeroIntensityZeroIntensity added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Aug 7, 2026
@miss-islington-app

Copy link
Copy Markdown

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

@miss-islington-app

Copy link
Copy Markdown

Thanks @lpyu001 for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

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

@bedevere-app

Copy link
Copy Markdown

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

@bedevere-appbedevere-appBot removed the needs backport to 3.14 bugs and security fixes label Aug 7, 2026
@bedevere-app

Copy link
Copy Markdown

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

@bedevere-appbedevere-appBot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 7, 2026
@bedevere-app

Copy link
Copy Markdown

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

@bedevere-appbedevere-appBot removed the needs backport to 3.13 bugs and security fixes label Aug 7, 2026
ZeroIntensity pushed a commit that referenced this pull request Aug 7, 2026
…s immortal in the code (GH-151525) (GH-155351)
(cherry picked from commit 52bed26)
Co-authored-by: stevens <lipengyu@kylinos.cn>
ZeroIntensity pushed a commit that referenced this pull request Aug 7, 2026
…s immortal in the code (GH-151525) (GH-155349)
(cherry picked from commit 52bed26)
Co-authored-by: stevens <lipengyu@kylinos.cn>
@bedevere-bot

Copy link
Copy Markdown

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

Hi! The buildbot AMD64 Arch Linux Asan Debug 3.13 (tierless) has failed when building commit 2e19855.

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/1439/builds/1152) and take a look at the build logs.
  4. Check if the failure is related to this commit (2e19855) 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/1439/builds/1152

Failed tests:

  • test_io

Failed subtests:

  • test_daemon_threads_shutdown_stdout_deadlock - test.test_io.CMiscIOTest.test_daemon_threads_shutdown_stdout_deadlock
  • test_daemon_threads_shutdown_stderr_deadlock - test.test_io.CMiscIOTest.test_daemon_threads_shutdown_stderr_deadlock

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

==

Click to see traceback logs
Traceback (most recent call last):
File "/buildbot/buildarea/3.13.pablogsal-arch-x86_64.asan_debug/build/Lib/test/test_io.py", line 4755, in test_daemon_threads_shutdown_stderr_deadlockself.check_daemon_threads_shutdown_deadlock('stderr')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/buildbot/buildarea/3.13.pablogsal-arch-x86_64.asan_debug/build/Lib/test/test_io.py", line 4743, in check_daemon_threads_shutdown_deadlockself.assertRegex(err, pattern)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
AssertionError: Regex didn't match: "Fatal Python error: _enter_buffered_busy: could not acquire lock for <(_io\\.)?BufferedWriter name='<stderr>'> at interpreter shutdown, possibly due to daemon threads" not found in '...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Traceback (most recent call last):
File "/buildbot/buildarea/3.13.pablogsal-arch-x86_64.asan_debug/build/Lib/test/test_io.py", line 4755, in test_daemon_threads_shutdown_stderr_deadlockself.check_daemon_threads_shutdown_deadlock('stderr')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/buildbot/buildarea/3.13.pablogsal-arch-x86_64.asan_debug/build/Lib/test/test_io.py", line 4743, in check_daemon_threads_shutdown_deadlockself.assertRegex(err, pattern)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
AssertionError: Regex didn't match: "Fatal Python error: _enter_buffered_busy: could not acquire lock for <(_io\\.)?BufferedWriter name='<stderr>'> at interpreter shutdown, possibly due to daemon threads" not found in '....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Traceback (most recent call last):
File "/buildbot/buildarea/3.13.pablogsal-arch-x86_64.asan_debug/build/Lib/test/test_io.py", line 4750, in test_daemon_threads_shutdown_stdout_deadlockself.check_daemon_threads_shutdown_deadlock('stdout')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/buildbot/buildarea/3.13.pablogsal-arch-x86_64.asan_debug/build/Lib/test/test_io.py", line 4743, in check_daemon_threads_shutdown_deadlockself.assertRegex(err, pattern)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^

@bedevere-bot

Copy link
Copy Markdown

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

Hi! The buildbot AMD64 Arch Linux Usan Function 3.13 (tierless) has failed when building commit 2e19855.

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/821) and take a look at the build logs.
  4. Check if the failure is related to this commit (2e19855) 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/821

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

Click to see traceback logs
Note: switching to '2e19855a1734a47780b42cfcdc9e3f31976c3e7c'.
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 2e19855a1734a [3.13] gh-151524: Make it clearer that `_PyInstrumentation_DISABLE` is immortal in the code (GH-151525) (GH-155351)
Switched to and reset branch '3.13'
rror: unable to open output file 'Python/pythonrun.o': 'No space left on device'
1 error generated.
make: *** [Makefile:3042: Python/pythonrun.o] Error 1find: ‘build’: No such file or directoryfind: ‘build’: No such file or directoryfind: ‘build’: No such file or directoryfind: ‘build’: No such file or directorymake: [Makefile:3132: clean-retain-profile] Error 1 (ignored)

hugovk pushed a commit that referenced this pull request Aug 8, 2026
…s immortal in the code (GH-151525) (#155350)
gh-151524: Make it clearer that `_PyInstrumentation_DISABLE` is immortal in the code (GH-151525)
(cherry picked from commit 52bed26)
Co-authored-by: stevens <lipengyu@kylinos.cn>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@lpyu001@aisk@bedevere-bot@sobolevn@ZeroIntensity@chris-eibl