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

Abierto Apto para principiantes
#32 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
84/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
backend, testing

Línea de trabajo

Lee internal/gateway/apps/ai_secrets_test.go, especialmente secretsFixture, y comprueba cómo obtienen un scanner las pruebas paralelas. El issue sugiere compartir un scanner por paquete con sync.OnceValues; verifica que Scanner admita el uso concurrente tal como se describe. Ejecuta go test -race ./internal/gateway/apps varias veces y confirma que la race ya no aparece.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
5
Forks
0
Merge medio
21 h 13 min
PR fusionados (30 d)
53

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nebari-dev/tapas

Todos los issues de nebari-dev/tapas

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.