jcalcote opened a new pull request, #1628:
URL: https://github.com/apache/ratis/pull/1628

   ## What changes were proposed in this pull request?
   
   Fix an updater shutdown hang when a synchronous state-machine callback 
failure races with server close.
   
   `stopAndJoin()` can pass its EXCEPTION check before the callback fails, then 
wait for the updater.
   The updater enters EXCEPTION and calls `server.close()`, but the division is 
already CLOSING, so
   that call does nothing. The updater cannot reach its stop index and 
continues looping in EXCEPTION.
   
   Use thread identity to avoid joining the updater from itself. Other callers 
join it rather than
   closing the state machine concurrently based on the exception state. In the 
exception handler,
   ensure the updater stops even when the division close was already underway. 
Preserve existing
   normal shutdown draining and avoid closing the state machine twice.
   
   The new unit test forces both orderings with latches and the real lifecycle 
close gate. It checks
   updater termination, completed shutdown, exactly-once close, and no 
applied-index advancement for
   the failed entry. It does not require an external application or 
disk-failure injection.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/RATIS-2731
   
   ## How was this patch tested?
   
   On unmodified production code, the new test's shutdown-before-exception case 
fails with
   `Failed updater did not terminate`; the exception-before-shutdown case 
passes.
   
   With the fix, five consecutive runs of the following selection passed (7 
tests per run):
   
   ```sh
   mvn -B -pl ratis-test -am test \
     
-Dtest=TestStateMachineUpdater,TestStateMachineShutdownWithGrpc,TestRaftStateMachineExceptionWithGrpc
 \
     -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false -Djacoco.skip
   ```
   
   The full reactor package build with tests skipped, project Checkstyle and 
Apache RAT license-header
   checks passed. SpotBugs passed for ratis-server and its reactor 
prerequisites using
   `mvn -B -pl ratis-server -am test-compile spotbugs:check -DskipTests 
-Djacoco.skip`.
   
   Validation used Maven 3.9.9 and Temurin Java 25 with the project's Java 8 
compiler release setting.
   The full test suite and multi-JDK matrix were not run locally.
   
   Prepared with assistance from OpenAI Codex and reviewed by the submitting 
contributor.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to