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

Aperta Adatta ai principianti
#32 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend, testing

Direzione di ricerca

Leggi internal/gateway/apps/ai_secrets_test.go, in particolare secretsFixture, e verifica come i test paralleli ottengono uno scanner. L’issue suggerisce di condividere uno scanner per package con sync.OnceValues; verifica che Scanner supporti l’uso concorrente come descritto. Esegui go test -race ./internal/gateway/apps ripetutamente e conferma che la race non si verifica più.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
5
Fork
0
Merge medio
21h 13m
PR unite (30g)
53

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nebari-dev/tapas

Tutte le issue di nebari-dev/tapas

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.