Flaky Test
TestMaintainerSchedule in maintainer/maintainer_test.go is flaky under race detector.
Symptom
CI occasionally reports:
WARNING: DATA RACE
- Read:
maintainer/maintainer_test.go:333
- Write:
maintainer/maintainer.go:880
Key stack path for write:
runHandleEvents (maintainer.go:1152)
HandleEvent (maintainer.go:340)
onMessage (maintainer.go:472)
onMaintainerPostBootstrapResponse (maintainer.go:880)
Reproduction
go test -race ./maintainer -run TestMaintainerSchedule -count=1
Root Cause Analysis
The test reads maintainer.postBootstrapMsg directly in an assert/require.Eventually closure:
maintainer_test.go:333: maintainer.postBootstrapMsg == nil
Eventually polls from another goroutine, while maintainer event loop goroutine writes:
maintainer.go:880: m.postBootstrapMsg = nil
maintainer.go:934: m.postBootstrapMsg = postBootstrapRequest
postBootstrapMsg is a plain pointer field without synchronization, so this is a genuine data race between test reader and maintainer writer.
Expected
TestMaintainerSchedule should be race-free and stable under -race.
Notes
ddlSpan.IsWorking() is not the primary issue here (it reads from atomic status); the race is on postBootstrapMsg.
Flaky Test
TestMaintainerScheduleinmaintainer/maintainer_test.gois flaky under race detector.Symptom
CI occasionally reports:
WARNING: DATA RACEmaintainer/maintainer_test.go:333maintainer/maintainer.go:880Key stack path for write:
runHandleEvents(maintainer.go:1152)HandleEvent(maintainer.go:340)onMessage(maintainer.go:472)onMaintainerPostBootstrapResponse(maintainer.go:880)Reproduction
go test -race ./maintainer -run TestMaintainerSchedule -count=1Root Cause Analysis
The test reads
maintainer.postBootstrapMsgdirectly in anassert/require.Eventuallyclosure:maintainer_test.go:333:maintainer.postBootstrapMsg == nilEventuallypolls from another goroutine, while maintainer event loop goroutine writes:maintainer.go:880:m.postBootstrapMsg = nilmaintainer.go:934:m.postBootstrapMsg = postBootstrapRequestpostBootstrapMsgis a plain pointer field without synchronization, so this is a genuine data race between test reader and maintainer writer.Expected
TestMaintainerScheduleshould be race-free and stable under-race.Notes
ddlSpan.IsWorking()is not the primary issue here (it reads from atomic status); the race is onpostBootstrapMsg.