runtime: NumGoroutine counts exiting goroutines, iter.TestPull flakes

Đang mở
#6,230 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, go

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Go
Star
17.8k
Fork
1.1k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
380

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tinygo-org/tinygo

Tất cả issue của tinygo-org/tinygo

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.