Repository navigation
Description
Problem
pkg/embed.TestBaseClusterCanWorkWithNewCluster can race during logservice shutdown: Dragonboat destroys a state machine while a detached HAKeeper task-scheduling goroutine is still executing SyncRead.
Observed in run 30603896298 / job 91072145422 at exact head 8410ce20f36f321a3ea8da32770d459feba34503:
WARNING: DATA RACE
Write:
dragonboat/internal/rsm.(*OffloadedStatus).SetDestroyed
dragonboat/internal/rsm.(*NativeSM).Close
dragonboat.(*node).destroy
Previous read:
dragonboat/internal/rsm.(*NativeSM).Lookup
dragonboat.(*NodeHost).SyncRead
logservice.(*store).read store.go:705
logservice.(*store).getCheckerState store_hakeeper_check.go:483
logservice.(*store).tickerForTaskSchedule store.go:1174
The test fails with race detected during execution of test.
Relationship to PR #26473
This is not a regression introduced by #26473:
- fix: stabilize lockservice RPC lifecycle under CI load #26473 does not modify
pkg/embed,pkg/logservice, or the Dragonboat dependency. - The race stack contains no lockservice or MORPC frame.
- The same CI run passed both
pkg/lockserviceandpkg/logservice; the race is exposed by embed cluster teardown. - On the exact PR head, the test passed
-race -count=3in 67.51s. - On pre-PR main
cf6dca31107769ad7855ebb45b1a6b48298284d6, it passed-race -count=3in 67.37s. - Existing [Bug]:ut TestBaseClusterCanWorkWithNewCluster failed #20604 has the same test name but a different root cause (port already in use), so it is not a duplicate.
Root cause
store.ticker starts task scheduling with an untracked goroutine:
go l.tickerForTaskSchedule(ctx, l.cfg.HAKeeperCheckInterval.Duration)store.close calls:
l.tickerStopper.Stop()
l.stopper.Stop()
l.nh.Close()Stopping tickerStopper waits for the parent ticker task, but not for the raw child goroutine. Cancellation also does not immediately fence its current read because getCheckerState() creates a new timeout context from context.Background(). Consequently l.nh.Close() may destroy the state machine while the detached goroutine is inside SyncRead.
Suggested fix
- Put
tickerForTaskScheduleunder structured ownership (the same stopper or an explicit wait group); do not launch it as an untracked goroutine. - Thread the ticker's cancellation context into
getCheckerStateWithContextso shutdown cancels an in-flightSyncRead. - Ensure
store.closejoins all NodeHost users before callingl.nh.Close(). - Add an unhappy-path race test that blocks task-scheduler
SyncRead, initiates close, and verifies close waits or cancels before NodeHost destruction. - Audit other raw goroutines that access
l.nhfor the same close-order invariant.
Acceptance criteria
TestBaseClusterCanWorkWithNewCluster -race -count=50is stable.- A deterministic test covers shutdown while task-schedule state lookup is in flight.
- No goroutine can enter or remain in NodeHost operations after the close sequence reaches
NodeHost.Close.
Activity
fix: join HAKeeper task scheduler before log store close (#26507)
LeftHandCold commentedon Jul 31, 2026
fixed
fix: join HAKeeper task scheduler before log store close (matrixorigi…
fix: join HAKeeper task scheduler before log store close (matrixorigi…
fix: join HAKeeper task scheduler before log store close (matrixorigi…