Race in gateway/apps tests: scanner.New called concurrently from parallel tests

Đang mở Phù hợp với người mới
#32 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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
backend, testing

Hướng nghiên cứu

Đọc internal/gateway/apps/ai_secrets_test.go, đặc biệt là secretsFixture, và kiểm tra cách các bài kiểm thử chạy song song lấy scanner. Issue đề xuất chia sẻ một scanner cho mỗi package bằng sync.OnceValues; hãy xác minh rằng Scanner hỗ trợ sử dụng đồng thời như được mô tả. Chạy go test -race ./internal/gateway/apps nhiều lần và xác nhận race không còn xuất hiện.

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

Mô tả

go test -race ./internal/gateway/apps fails now and then with DATA RACE in tests that have nothing in common, such as TestExplainOfAHealthyAppIsRefused, TestTemplateListCarriesMaxSharing and TestNonMemberCannotCreate. Locally it failed 2 of 7 runs. CI has been green, so it may only show up under load.

The race is two goroutines writing viper's global config:

Write at ... by goroutine 61:
  github.com/spf13/viper.(*Viper).SetConfigType()          [email protected]/viper.go:2189
  github.com/zricethezav/gitleaks/v8/detect.NewDetectorDefaultConfig()  detect.go:136
  github.com/nebari-dev/javo/internal/ai/redact/scanner.New()  scanner.go:32
  .../gateway/apps_test.secretsFixture()                      ai_secrets_test.go:22
  .../gateway/apps_test.TestInjectedLogTextChangesNothing()   ai_injection_test.go:20
Previous write ... by goroutine 62:
  ... same path via TestExplainBundleIsShownOnlyToTheOwner()  ai_secrets_test.go:58

scanner.New says "Call it once at start-up: the rules are parsed through viper's global instance" (internal/ai/redact/scanner/scanner.go:29-30). The gateway does call it once. The test helper secretsFixture (internal/gateway/apps/ai_secrets_test.go:20) calls it for every test, and those tests run with t.Parallel(), so two of them can parse gitleaks' rules at the same time. When the race detector fires, it fails whichever tests are running then, which is why the failing names vary.

Production is not affected. The fix is in the tests: build one scanner per package (for example with sync.OnceValues in the test file) and share it, since Scanner already guards its detector with a mutex. Making New itself safe to call concurrently would also work, but it would hide the "once at start-up" contract instead of keeping it.

Ngôn ngữ chính
Go
Star
5
Fork
0
Merge trung bình
21 giờ 13 phút
Pull request đã merge (30 ngày)
53

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

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 nebari-dev/tapas

Tất cả issue của nebari-dev/tapas

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.