Fix: Prevent race condition during pipe registration

This change introduces thread-safe pipe registration and unregistration functions using `sync.WaitGroup` and `atomic.Int64` to manage the count of registered pipes, addressing a race condition identified by the race detector.
This commit is contained in:
Eric Coissac committed 2026-11-03 22:34:22 +11:00
1 parent 56f5fe33d7
commit f75e774bd5
2 files changed
+8 -6

No files matched your search

+2 -1
View File
@@ -245,7 +245,8 @@ de la taxonomie et du FASTA non comprise ; ecoPrimers complet : 134 s et 350 s (
**Bug existant repéré hors périmètre** : `go test -race` signale une course dans
`obiutils/pipe.go` (`globalLockerCounter` est un `int` incrémenté et décrémenté depuis plusieurs
goroutines, utilisé seulement pour des `log.Debugln`). Sans rapport avec obiprimers ; un `atomic.Int64`
suffirait. Non modifié (code partagé) : à décider.
suffisait. **Corrigé** (accord de l'utilisateur) : `globalLockerCounter` est un `atomic.Int64` dans
`pkg/obiutils/pipe.go` ; le test de bout en bout passe désormais sous `-race`.
Suite : étape 3 (recherche approchée des mots stricts, <= e substitutions, deux brins, dans exemples
et contre-exemples), puis paires et indices.
+6 -5
View File
@@ -2,12 +2,13 @@ package obiutils
import (
"sync"
"sync/atomic"
log "github.com/sirupsen/logrus"
)
var globalLocker sync.WaitGroup
var globalLockerCounter = 0
var globalLockerCounter atomic.Int64
// RegisterAPipe increments the global lock counter and adds a new pipe to the global wait group.
//
@@ -15,8 +16,8 @@ var globalLockerCounter = 0
// No return values.
func RegisterAPipe() {
globalLocker.Add(1)
globalLockerCounter++
log.Debugln(globalLockerCounter, " Pipes are registered now")
n := globalLockerCounter.Add(1)
log.Debugln(n, " Pipes are registered now")
}
// UnregisterPipe decrements the global lock counter and signals that a pipe has finished.
@@ -25,8 +26,8 @@ func RegisterAPipe() {
// No return values.
func UnregisterPipe() {
globalLocker.Done()
globalLockerCounter--
log.Debugln(globalLockerCounter, "are still registered")
n := globalLockerCounter.Add(-1)
log.Debugln(n, "are still registered")
}
// WaitForLastPipe waits until all registered pipes have finished.