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

オープン 初心者向け
#32 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
backend, testing

調査の方向性

internal/gateway/apps/ai_secrets_test.go、特に secretsFixture を読み、並列テストがどのように scanner を取得しているか確認してください。issue では sync.OnceValues を使ってパッケージごとに1つの scanner を共有することを提案しています。説明どおり Scanner が並行使用に対応しているか確認してください。go test -race ./internal/gateway/apps を繰り返し実行し、race が発生しなくなったことを確認してください。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Go
スター
5
フォーク
0
平均マージ
21時間 13分
マージ済み PR(30日)
53

環境構築

はじめの一歩

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

nebari-dev/tapas のほかの issue

nebari-dev/tapas の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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