fix: protect all r.closed accesses, add race test, enable -race in CI

The initial `if r.closed` guard in RunDaemon() was still reading
r.closed without holding closedM, causing a data race with Close().
Wrap it with closedM to match the other access sites.

Add TestReporter_RunDaemonClose_Race which exercises RunDaemon() and
Close() concurrently — the exact scenario from #793. Without the fix,
`go test -race` reliably detects the data race.

Enable the -race flag in `make test` so CI catches data races.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
silverwind
2026-02-19 02:54:45 +01:00
parent 5591f0a546
commit a4a6e291d5
3 changed files with 48 additions and 1 deletions

View File

@@ -178,9 +178,13 @@ func (r *Reporter) Fire(entry *log.Entry) error {
}
func (r *Reporter) RunDaemon() {
r.closedM.Lock()
if r.closed {
r.closedM.Unlock()
return
}
r.closedM.Unlock()
if r.ctx.Err() != nil {
return
}