Skip to content

flaky test: data race in TestMaintainerSchedule on postBootstrapMsg #4297

@3AceShowHand

Description

@3AceShowHand

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.

Metadata

Metadata

Assignees

Labels

component/testUnit tests and integration tests component.type/enhancementThe issue or PR belongs to an enhancement.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions