You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test_io failed with ASAN failures (heap-use-after-free) on AMD64 Arch Linux Asan 3.13 #154175
changed the title [-]test_io failed with ASAN failures on AMD64 Arch Linux Asan 3.13[/-][+]test_io failed with ASAN failures (heap-use-after-free) on AMD64 Arch Linux Asan 3.13[/+]on Jul 19, 2026
Both test_daemon_threads_shutdown_stdout_deadlock and test_daemon_threads_shutdown_stderr_deadlock pass locally.
Repeated execution (-F) also passes consistently on my release build.
I couldn't reproduce the reported heap-use-after-free outside of the ASAN buildbot.
I also didn't find any recent changes in Lib/test/test_io.py or Modules/_io that appear related.
Since the buildbot log only contains the beginning of the AddressSanitizer report, I'm currently missing the stack trace showing where the use-after-free originates.
Would it make sense to investigate this further only with an ASAN build, or is there another area of the runtime that is already suspected?
The test relies on time.sleep(0.5) to get the I/O stack blocked in a particular way which isn't great. There are tests in test_threading to make sure that an interpreter with daemon threads shuts down okay so I'd like to change this test_io to use a mocked Raw I/O which can use threading.Event to trigger the locking contention explicitly. That applies from main down to 3.13.
We could add an ASAN suppression to parallel the TSAN one but my leaning is just moving under the GIL a couple lines earlier.
Well, since the HangThread changes weren't backported, daemon threads in 3.13 feel like a lost cause. If we handle the dangling tstate that in drop_gil, won't that just move the use-after-free to the next take_gil?
I think the drop_gil_impl call is what enables the tstate go from "definitely allocated" to "maybe allocated" and why we hit the ASAN failure. There are cases where tstate could be passed as NULL but I think the failure if we were hitting those would be a bit different.
Daemon threads are used by quite a few projects... we can definitely just silence this particular test but not sure how that will be for SRE type work in deployments.
Activity
[-]test_io failed with ASAN failures on AMD64 Arch Linux Asan 3.13[/-][+]test_io failed with ASAN failures (heap-use-after-free) on AMD64 Arch Linux Asan 3.13[/+]BHUVANSH855 commentedon Jul 25, 2026
I investigated this on the
3.13branch.So far I've found that:
test_daemon_threads_shutdown_stdout_deadlockandtest_daemon_threads_shutdown_stderr_deadlockpass locally.-F) also passes consistently on my release build.Lib/test/test_io.pyorModules/_iothat appear related.Since the buildbot log only contains the beginning of the AddressSanitizer report, I'm currently missing the stack trace showing where the use-after-free originates.
Would it make sense to investigate this further only with an ASAN build, or is there another area of the runtime that is already suspected?
cmaloney commentedon Aug 29, 2026
Have two potential improvements here:
_Py_eval_breaker_bit_is_setaccesseststateand, in 3.13, a finalizing main thread may free thetstateresulting in the use after free. For main this was fixed in race condition in threading when interpreter finalized while daemon thread runs (thread sanitizer identified) #124878 and suppressed in TSAN for 3.13. We could add an ASAN suppression to parallel the TSAN one but my leaning is just moving under the GIL a couple lines earlier.cpython/Python/ceval_gil.c
Line 266 in 87c9dfb
time.sleep(0.5)to get the I/O stack blocked in a particular way which isn't great. There are tests intest_threadingto make sure that an interpreter with daemon threads shuts down okay so I'd like to change thistest_ioto use a mocked Raw I/O which can usethreading.Eventto trigger the locking contention explicitly. That applies frommaindown to 3.13.encukou commentedon Sep 9, 2026
Well, since the
HangThreadchanges weren't backported, daemon threads in 3.13 feel like a lost cause. If we handle the danglingtstatethat indrop_gil, won't that just move the use-after-free to the nexttake_gil?cmaloney commentedon Sep 14, 2026
I think the
drop_gil_implcall is what enables the tstate go from "definitely allocated" to "maybe allocated" and why we hit the ASAN failure. There are cases wheretstatecould be passed as NULL but I think the failure if we were hitting those would be a bit different.Daemon threads are used by quite a few projects... we can definitely just silence this particular test but not sure how that will be for SRE type work in deployments.
[3.13] gh-154175: Fetch _PY_GIL_DROP_REQUEST_BIT under GIL (#157013)
gh-154175: Remove time.sleep in test_io daemon test (#157019)