runtime: NumGoroutine counts exiting goroutines, iter.TestPull flakes

未关闭
#6,230 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
c, go

调研方向

Start with tinygo_task_exited in src/internal/task/task_threads.c (around line 98), where the threads scheduler stops counting an exiting goroutine, and with the GOMAXPROCS stub in src/runtime/runtime.go (around line 30). Reproduce by running the upstream iter TestPull repeatedly on the threads scheduler and watch the goroutine counts. Done means TestPull passes reliably, for example by making NumGoroutine exclude goroutines that have finished, or by making the baseline wait for them to exit.

由索引模型根据 Issue 内容生成。

描述

iter's TestPull is upstream Go's test, run unchanged from GOROOT. It failed once in CI on an unrelated PR (#6229), in the assert-stdlib-test-linux job:

https://github.com/tinygo-org/tinygo/actions/runs/42597317396/job/129094472336

--- FAIL: TestPull (0.01s)
    --- FAIL: TestPull/1 (0.00s)
        have 0 extra goroutines, want 1
        have 0 extra goroutines, want 1
        have 0 extra goroutines, want 1
        have -1 extra goroutines, want 0
        have -1 extra goroutines, want 0
        have -1 extra goroutines, want 0
        have -1 extra goroutines, want 0
        have -1 extra goroutines, want 0
FAIL	iter	0.030s

The first wantNG(0) passed, and every check after Pull was one low. So a goroutine that was counted in the baseline exited during the subtest.

On Linux the threads scheduler stops counting a goroutine in tinygo_task_exited. That runs after the goroutine function returns (src/internal/task/task_threads.c:98). t.Run returns as soon as the subtest goroutine signals it is done, so TestPull/0's thread can still be counted when TestPull/1 takes its baseline. Upstream stableNumGoroutine uses GOMAXPROCS(1) and Gosched to let other goroutines finish first. TinyGo ignores GOMAXPROCS (src/runtime/runtime.go:30), so on the threads scheduler the baseline can include a goroutine that is about to exit.

主要语言
Go
星标
17.8k
派生
1.1k
平均合并
1 天 4 小时
30 天内合并 PR
380

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tinygo-org/tinygo 的其他 Issue

查看 tinygo-org/tinygo 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

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