[Bug] Late Raft leader callbacks submit metadata after apply queue shutdown

Author: slievrlyCreated Sep 26, 2026Updated Sep 26, 2026

Check Ahead

  • Searched existing issues for applyQueue shutdown errors.
  • Willing to fix.

Issue Description

RaftServer.destroy shuts down the Raft group while a queued leader-start callback can still call RaftStateMachine.syncMetadata. That callback submits a task after JRaft has cleared its applyQueue, causing a NullPointerException which syncMetadata logs and swallows.

Evidence

Java 17 CI job, commit 96e84e52f, raw lines 32366-32389 during BranchSessionExecuteTest teardown. Stack: NodeImpl.apply -> RaftTaskUtil.createTask -> syncMetadata -> onLeaderStart -> ConfigurationChangeDone. Node shutdown is already underway and onLeaderStop follows. This is a lifecycle race, not an injected null queue test.

Expected behavior

Quiesce metadata submission before shutting down JRaft. Delayed leader callbacks must not restore leadership or submit new tasks, and pending metadata retries should be cancelled.

Environment

Seata 2.8.0-SNAPSHOT, Java 17, Raft session mode.