[BUG] Instance checker skips executor shutdown when its final database sync fails
Current behavior
InstanceCheckService.close() invokes syncDB() before clearing the local map and calling executor.shutdown(). There is no finally block. When InstanceInfoService.createOrUpdate throws during the final flush, execution exits before executor cleanup.
The checker executor is created with non-daemon threads. This can leave scheduled checking/persistence work active after the bean's shutdown callback fails and can interfere with graceful process/context shutdown. This path also appears when close() is called during cluster error handling. The exact process-exit effect depends on the surrounding shutdown lifecycle.
Source evidence
- Close ordering without finally
- Non-daemon executor creation
- Database call can throw on update
- Cluster error cleanup caller
Deterministic regression scenario
Initialize the checker and add an observed instance. Configure a mock persistence service to throw during the final synchronization. Invoke close() and verify the owned executor is shut down and cleanup completes even though persistence failed. Clean up any test-owned threads unconditionally. No long sleeps or real database outage is needed for this regression.
This issue was verified by source/control-flow inspection; the regression and a process-level graceful-shutdown test were not run during issue preparation.
Acceptance criteria
- [ ] Executor/resource cleanup runs regardless of final persistence success or failure.
- [ ] Stop accepting/scheduling new work and bound any waiting for outstanding work; preserve explicit behavior for failure of the best-effort final flush.
- [ ] Avoid clearing state while still-running tasks can repopulate or persist it without a documented lifecycle policy.
- [ ] Test final-flush failure, normal shutdown, repeated close and close-before-setup with deterministic executor assertions.
- [ ] Test cleanup ordering in the cluster error path without masking the original cause; no non-daemon checker thread remains after the documented shutdown bound.
Related: #6496 covers periodic sync cancellation after an exception, not cleanup in close. #6705 fixed the null executor when setup never ran; its existing no-setup test does not cover final-flush failure. #7744 concerns scheduler starvation by slow persistence.
Fault verification update (2026-10-17)
Reproduced against 66d7d954ca37d651a5ad916f988a8081157a7ab4 using the current InstanceCheckService source recompiled on Java 17, with a controlled persistence implementation throwing from createOrUpdate during close().
Observed: close() threw the injected exception and executor.isShutdown() was still false. The fixture then explicitly shut down/awaited its executor in finally. This verifies skipped cleanup; a full process shutdown hang was not tested.
The normal startup-delayed tasks were cancelled in the fixture to avoid waiting; no production source was changed. Supporting dependencies came from local build artifacts. This is a focused reproduction, not a full Maven/deployment test.
/assign
Hi @Aias00 and @harshkha3417, I have prepared a local fix and deterministic regression tests for #7748, and noticed that #7749 also changes close() and includes a final-sync failure test.
My current work additionally covers draining scheduled work before the final flush, bounded executor termination with interruption, retaining state if termination fails, rejecting heartbeats after close, repeated close/restart, and preserving the original master-selection exception when cleanup fails.
The focused local verification passes 35 tests with Checkstyle and RAT. Three selected regression cases fail against the original production code.
Would you prefer that I adapt these lifecycle improvements/tests for #7749, or open a separate follow-up PR? I have not opened a PR for this work yet and would like to avoid duplicating the existing effort.