FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-74112: Fix race in test_interrupt_blocking_call by christianaurichzm · Pull Request #158914 · python/cpython · GitHub

Repository navigation

gh-74112: Fix race in test_interrupt_blocking_call - #158914

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
christianaurichzm:gh-74112-interrupt-test-race
Oct 6, 2026
Merged

serhiy-storchaka merged 1 commit into
python:mainfrom
christianaurichzm:gh-74112-interrupt-test-race

Conversation

christianaurichzm commented Oct 6, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor

InterruptTest.test_interrupt_blocking_call (added in gh-157662) started the timer that sends SIGINT before entering the assertRaises() block:

timer.start()
start = time.monotonic()
with self.assertRaises(KeyboardInterrupt):
    time.sleep(support.SHORT_TIMEOUT)

If the main thread takes more than 0.1 seconds to get from timer.start() to time.sleep(), the KeyboardInterrupt is raised outside the block. It escapes the test, and regrtest stops the whole run ("Test suite interrupted by signal SIGINT"). This happened on the AMD64 Windows Server 2022 NoGIL buildbot, as reported in gh-74112, and in the "macOS (free-threading)" job on #158910 and #158828. In all three cases the build was free-threaded and the machine was loaded.

This change starts the timer inside the block, so the interrupt is caught wherever it arrives.

Verification

I ran the real test 300 times in a loop on a free-threaded debug build, with 48 busy processes on 16 cores:

  • before: the KeyboardInterrupt escaped the test in 46 out of 300 runs
  • after: 0 out of 300

On the default build it did not reproduce under the same load (0 out of 500 before and after). There the timer thread needs the GIL to send the signal, which in practice hides the window. test_idle passes on both builds.

The timer that sends SIGINT was started before entering the
assertRaises() block. On a loaded machine the KeyboardInterrupt could
be raised before the main thread reached time.sleep(), escape the test
and stop the whole regrtest run. Start the timer inside the block.

serhiy-storchaka 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. 👍 Thank you for the analysis and the fix.

serhiy-storchaka added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes skip news needs backport to 3.15 pre-release feature fixes, bugs and security fixes and removed needs backport to 3.13 only security fixes labels Oct 6, 2026
serhiy-storchaka enabled auto-merge (squash) October 6, 2026 15:03
serhiy-storchaka merged commit ea0ee92 into python:main Oct 6, 2026
67 checks passed

Copy link
Copy Markdown

Thanks @christianaurichzm for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

Copy link
Copy Markdown

Sorry, @christianaurichzm and @serhiy-storchaka, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker ea0ee925ad755999d6095ba61de2652ec9275f04 3.15

bedevere-app Bot commented Oct 6, 2026

Copy link
Copy Markdown

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

bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 6, 2026
serhiy-storchaka pushed a commit to miss-islington/cpython that referenced this pull request Oct 6, 2026
…8914)

On a loaded machine the KeyboardInterrupt could be raised before the main
thread reached time.sleep(), escape the test and stop the whole regrtest run.

(cherry picked from commit ea0ee92)
serhiy-storchaka removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 6, 2026

Copy link
Copy Markdown
Member

I cherry-picked this change in #158917, so no separate backport to 3.15 is needed.

serhiy-storchaka pushed a commit that referenced this pull request Oct 6, 2026
…GH-158920)

On a loaded machine the KeyboardInterrupt could be raised before the main
thread reached time.sleep(), escape the test and stop the whole regrtest run.
(cherry picked from commit ea0ee92)

Co-authored-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>

Copy link
Copy Markdown

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

Hi! The buildbot aarch64 Fedora Stable Refleaks 3.x (tier-2) has failed when building commit ea0ee92.

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

Failed tests:

  • test_profiling
  • test.test_asyncio.test_events

Failed subtests:

  • test_cprofile - test.test_profile.ProfileTest.test_cprofile
  • test_create_connection_local_addr_skip_different_family - test.test_asyncio.test_events.SelectEventLoopTests.test_create_connection_local_addr_skip_different_family

Test leaking resources:

  • test_manager: references
  • test_manager: memory blocks

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

==

Click to see traceback logs
Traceback (most recent call last):
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-aarch64/3.x.cstratak-fedora-stable-aarch64.refleak/build/Lib/test/test_asyncio/test_events.py", line 825, in test_create_connection_local_addr_skip_different_family
    with self.assertRaises(OSError):
         ~~~~~~~~~~~~~~~~~^^^^^^^^^
AssertionError: OSError not raised


Traceback (most recent call last):
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-aarch64/3.x.cstratak-fedora-stable-aarch64.refleak/build/Lib/test/test_profile.py", line 70, in test_cprofile
    self.fail("\n".join(fail))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^
AssertionError: 
Stats.print_stats output for Profile does not fit expectation:
--- 
+++ 
@@ -1,7 +1,7 @@
        28   27.972    0.999   27.972    0.999 profilee.py:110(__getattr__)
-        1  269.996  269.996  999.769  999.769 profilee.py:25(testfunc)
-     23/3  149.937    6.519  169.917   56.639 profilee.py:35(factorial)
-       20   19.980    0.999   19.980    0.999 profilee.py:48(mul)
+        1  269.997  269.997  999.816  999.816 profilee.py:25(testfunc)
+     20/3  163.969    8.198  169.963   56.654 profilee.py:35(factorial)
+        6    5.994    0.999    5.994    0.999 profilee.py:48(mul)
         2   39.986   19.993  599.830  299.915 profilee.py:55(helper)
         4  115.984   28.996  119.964   29.991 profilee.py:73(helper1)
         2   -0.006   -0.003  139.946   69.973 profilee.py:84(helper2_indirect)


Traceback (most recent call last):
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-aarch64/3.x.cstratak-fedora-stable-aarch64.refleak/build/Lib/test/support/__init__.py", line 970, in gc_collect
    gc.collect()
    ~~~~~~~~~~^^
ResourceWarning: unclosed <socket.socket fd=5, family=2, type=1, proto=6, laddr=('127.0.0.1', 57745), raddr=('127.0.0.1', 57745)>
Warning -- Unraisable exception
Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0xffff8e8abad0>:
Traceback (most recent call last):
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-aarch64/3.x.cstratak-fedora-stable-aarch64.refleak/build/Lib/asyncio/selector_events.py", line 882, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ResourceWarning: unclosed transport <_SelectorSocketTransport fd=5>

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL