Potential thread unsafety in test_free_threading.test_monitoring
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
It seems that there is some kind of race with test_free_threading.test_monitoring, specifically the sys.settrace tests:
https://github.com/python/cpython/blob/fba5dded6df3c2b1943557afef89a5cb418f65a2/Lib/test/test_free_threading/test_monitoring.py#L143-L166.
This was initially spotted in a buildbot failure here: https://buildbot.python.org/#/builders/1610/builds/1590. There have been a few behaviors noted:
- refleaks causing a test failure
- assertion failures
- presumed deadlocks or other contention causing the tests to run extremely slowly (timing out after 45 minutes)
- tests pass without issue 😬
The variety of failure modes makes me think there is some kind of thread safety issue lurking behind the failures...
After some local debugging (the remote debugger rocks!), I was able to reproduce the extremely long test run of test_freethreading, and narrow down the majority of the time being in the sys.settrace tests. My command line was:
./python -E -m test --timeout=2700 -R 3:3 -u-cpu -j10 test_free_threading
On my x86 laptop on Ubuntu 24.04/WSL.
Reading over the test, it isn't clear to me what is meant to be tested. sys.settrace only affects the current thread according to the docs (indeed, the C code sets the trace function to the current threadstate), so currently it is only checking that the main thread executes a frame of some sort.
I didn't have time to find the root cause of the weird behavior above, so I'm filing this bug to note down my findings.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Lib/test/test_free_threading/test_monitoring.py 的第 143-166 行開始,並使用 ./python -E -m test --timeout=2700 -R 3:3 -u-cpu -j10 test_free_threading 重現問題。結合連結的 buildbot 失敗,調查 sys.settrace 測試,並確定 race、競爭或洩漏的來源。瞭解失敗模式,且受影響的測試能可靠執行,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- testing-qa
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 35/100