-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Heisenbug that kills process via SIGALRM #133687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I haven't looked at the reproducer yet, but this is understandable if unexpected behavior. Exceptions raised during destructors (i.e., https://docs.python.org/3/library/sys.html#sys.unraisablehook That's not new behavior and it's pretty much a fundamental limitation of raising exception asynchronously, such as with |
Interesting, so are you saying that raising an exception is always undefined behavior in Python, always has been? The thing that makes me quite curious is that I do believe that in the scenario, this does look like it is well-defined behavior. I'm setting Can you try to elaborate why this would be happening? I would be fine with the exception being omitted (e.g., during Thanks for taking the time to read through my report! Cheers. |
There are signals involved here, and those result in asynchronous code execution in C. Integration of signal handlers in the rest of the interpreter is non-trivial. Anyway:
|
Bug report
Bug description:
First of all, I know exactly how this bug is going to sound: batshit insane. I implore you to keep reading.
I've had a timer application for ages that uses
signal.alarm()
concurrently withinput()
so that it has a rudimentary way of displaying things in the background while still allowing user interaction on the CLI. The gist of it is this:This program has mysteriously stopped working with Python 3.13.3 with an exceptionally strange error mode: my signal handler is called from somewhere I apparently do not expect (
HelpFormatter
), causing the whole process to terminate. This always happens after exactly 29 seconds when I run my process as user and after exactly 25 seconds when I run as root. It happens only when there is no__pycache__
present, i.e., when the Python bytecode is generated on startup.I tried creating a minimal reproducer, which was super difficult. Even when I remove dead code from the Python script, the bug stops triggering. Some code removal was fine, but for example if I remove the wrapper around
argparse
, the bug disappears.As I said. This sounds batshit crazy.
When the mystery signal is caught, it gives one final indication where it comes from:
Note the message:
Exception ignored in tp_clear of HelpFormatter:
(this was running as root, you see that it took 25 seconds.)Just so you believe me that it always triggers after the same time, here are three consecutive runs as root (I swear this is not copy paste, timings are accurate to millisecond level!):
And here some runs as user:
I'm running on 6.14.0-15-generic #15-Ubuntu. My CPU is an AMD Ryzen Threadripper PRO 3945WX 12-Cores. I'm using the Ubuntu-provided Python package (Ubuntu calls it 3.13.3-1):
I cannot reproduce this issue on Debian with Python 3.11/ARM nor on another Ubuntu with Python 3.12/x86_64.
I cannot attach files (the reproducer) to this bug, so here it is as base64:
You can simply unpack it by doing:
And pasting the above base64 blob in. Remember you have to clear
__pycache__
to trigger the bug. I'm including the bytecode in case it contains something interesting.Please someone tell me this is reproducible and I'm not completely losing my marbles.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: