[
https://issues.apache.org/jira/browse/RATIS-2731?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tsz-wo Sze resolved RATIS-2731.
-------------------------------
Fix Version/s: 3.4.0
Assignee: John Calcote
Resolution: Fixed
The pull request is now merged. Thanks, [[email protected]]!
> StateMachineUpdater can hang indefinitely when an apply exception races with
> server shutdown
> --------------------------------------------------------------------------------------------
>
> Key: RATIS-2731
> URL: https://issues.apache.org/jira/browse/RATIS-2731
> Project: Ratis
> Issue Type: Bug
> Components: server
> Affects Versions: 3.3.1
> Reporter: John Calcote
> Assignee: John Calcote
> Priority: Major
> Fix For: 3.4.0
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> A synchronous state-machine callback failure can race with
> RaftServer.close(), leaving shutdown waiting indefinitely for a
> StateMachineUpdater that remains running in EXCEPTION state.
> Observed with Apache Ratis 3.3.1 in a three-peer integration test using gRPC.
> Thread dumps captured before the test timeout show the shutdown worker
> waiting in StateMachineUpdater.stopAndJoin(), while the updater remains
> RUNNABLE.
> *Failure sequence*
> # An external thread starts RaftServer.close(). A division shutdown worker
> enters StateMachineUpdater.stopAndJoin().
> # The updater has not yet entered EXCEPTION state, so stopAndJoin() passes
> its initial exception-state check, records stopIndex, and calls
> updater.join().
> # A state-machine callback on the updater thread throws synchronously. In our
> reproduction this is notifyTermIndexUpdated(), which rejects further
> application after a consensus-log I/O failure.
> # StateMachineUpdater.run() catches the exception, sets state = EXCEPTION,
> and calls RaftServerImpl.close().
> # The division is already CLOSING, so that close call does not execute its
> cleanup again.
> # The updater's outer loop continues because it exits only for STOP.
> EXCEPTION prevents further log application, but shouldStop() remains false
> because the applied index is below stopIndex.
> The updater therefore spins, and the shutdown worker remains blocked joining
> it. In the captured run, the applied index was 3 and stopIndex was 4.
> *Reproduction context and evidence*
> The integration test blocks one follower during application of a committed
> mutation, injects a log-write failure by closing its log FileChannel, waits
> for notifyLogFailed(), and releases the blocked application. The application
> fences subsequent state-machine callbacks after the log failure. The test
> then closes and restarts the failed follower.
> Three consecutive isolated runs passed; the fourth reproduced the hang.
> Thread dumps at 60 and 100 seconds showed the same waiting shutdown worker
> and running updater. At 120 seconds, the test framework interrupted the
> caller, which caused close() to return with the interrupt flag set. A
> subsequent restart then failed with InterruptedIOException. The restart
> exception was a consequence of the shutdown hang, not the initial failure.
> A standalone Ratis-only reproducer has not yet been prepared.
> *Expected behavior*
> A fatal synchronous state-machine callback failure during shutdown should
> allow the updater to terminate and shutdown to complete. It must not require
> successful application of the entry that failed.
> *Related issues*
> RATIS-1119 introduced the EXCEPTION check in stopAndJoin(), handling the case
> where the updater has already failed before that method is entered. This
> report concerns the opposite ordering: the exception occurs after that check.
> RATIS-1691 fixed a different shutdown cycle involving the proxy executor. Its
> fix is present in 3.3.1.
> The same exception-check and updater-loop logic is also present in upstream
> master at commit 5ea5c48f57a836f7bb12d74c1c32df4e955bd8a5.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)