python / python/cpython

Potential thread unsafety in test_free_threading.test_monitoring

未关闭
#135,633 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

tests topic-free-threading type-bug
主要语言
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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 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

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。