runtime: NumGoroutine counts exiting goroutines, iter.TestPull flakes

オープン
#6,230 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
380

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tinygo-org/tinygo のほかの issue

tinygo-org/tinygo の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。