Repository navigation
[2.0.x] fix: wait for the database at startup; quieter logs when stopping a sync that is not running (backport of #1333) - #1346
Conversation
…sync that is not running - Flyway retries the first database connection (30 retries, up to 10 s apart), and Hikari no longer fails at pool creation. The app no longer exits when it starts before Postgres is ready, for example after a host restart (fault-injection scenario J09, #1328). - Stopping a range fetch or chain sync that was never started or is already closed logs one warning line instead of a stack trace (#1314). Part of #1328. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit bc8bd0f)
… stop errors
Review: Spring Boot resolves Flyway's {vendor} location through the DataSource
before Flyway's connect-retries apply, so the retries never ran. Replace them
with a small BeanPostProcessor that retries a connection right after the
DataSource is created (store.db.startup-wait-seconds, default 300, 0 = off).
Only the NullPointerException yaci throws for a session that was never started
gets the one-line log; other stop errors keep their stack trace.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f4b487a)
|
Initial automated review · Aster Hi @satran004, thanks for the PR! 🙏 This is an automatic first check by an AI reviewer. It does not replace maintainer review and may be wrong. Reviewed commit: Issues found:
Not tested: I reviewed the code and CI without running the build, tests, or a database outage scenario. |
Fault-injection result on release/2.0.xThe same scenarios as #1328 ran on plain
Full results: #1339. This PR in the run: J09 (app and Postgres killed together, as in a host crash) during the initial sync: on plain 2.0.x the app exited because it started before Postgres, and needed a manual start. With this fix it waited for the database and recovered in 50 s. |
reviewer1 — review of
|
Review: the deadline was only checked after a failed attempt, and the pause before the next attempt was always 5 s. With store.db.startup-wait-seconds=1 and a refused connection the wait took about 5 s and made a second attempt after the budget was already used up. Now the pause is capped to the time left, and no attempt starts once the budget is used up. A single getConnection() that hangs is still bounded by the pool/driver connection timeout, not by this wait; the class comment says so. The clock and sleep are injectable so the tests check the timing without waiting. Added tests for a 1 s budget, the capped last pause, an attempt that uses up the budget, a real-clock 1 s budget, and interruption. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MJrQUCWhJpLCQR5Asv7nDb (cherry picked from commit 76cc063)
The last pause is capped to the time left, so it ends at the deadline. Try once more then instead of giving up right after the pause, so a database that comes up within the budget is still used. No attempt starts after the deadline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MJrQUCWhJpLCQR5Asv7nDb (cherry picked from commit 08b7df4)
|
Thanks, reviewer1. Handled as follows:
Commits: 9988540, 86d475f here, 76cc063, 08b7df4 on #1333. The fixes were made in #1333 first and cherry-picked here. Each finding, its verdict and its test are in the reply on #1339. The fault suite is running again on the updated combined build. |
|
Verdict: CHANGES REQUESTED reviewer1 — round 2. Reviewed F1 [P2] is partially resolved. Capping the pause fixes the original five-second oversleep for short budgets. Allowing an attempt exactly at the deadline is acceptable, but the implementation still starts attempts after it. F1 [P2], completion of the original finding. DatabaseStartupWait.java:84: after sleeping, the loop retries without checking the clock. A deterministic probe against the actual class uses a 1,000 ms budget and a sleeper that resumes 1,000 ms late. Output: Please recheck the clock before a retry and stop when it is greater than the deadline; equality can retain the requested final attempt. Add one oversleep test. No larger retry redesign is needed. Validation: seven module suites on isolated combined commit Exact commandJAVA_HOME=/Users/satya/.sdkman/candidates/java/21.0.3-tem ./gradlew :components:core:test :components:common:test :stores:assets:test :stores:metadata:test :stores:script:test :stores:mir:test :stores:staking:test --no-daemon --console=plainNo implementation changes made by this review. The updated VM fault-suite results are still pending. This verdict covers the reviewed head only. |
The last pause ends at the deadline, but the thread can wake up late (scheduling, GC, a suspended process), and the next attempt then started after the deadline. Check the clock after the pause: an attempt at the deadline is still made, a later one is not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MJrQUCWhJpLCQR5Asv7nDb (cherry picked from commit b3726b0)
|
|
Verdict: APPROVED reviewer1 — round 3. Reviewed F1 [P2]: Resolved. The post-sleep clock check rejects a retry after the deadline while allowing equality. The new oversleep regression covers the missing case. No further change requested. Validation on this exact head in an isolated checkout: 10 tests passed, none failed or skipped: JAVA_HOME=/Users/satya/.sdkman/candidates/java/21.0.3-tem ./gradlew :components:core:test --tests com.bloxbean.cardano.yaci.store.core.configuration.DatabaseStartupWaitTest --no-daemon --console=plainThe independent round-2 oversleep probe now reports |
|
Author reply: round r2 · head 22aaa9e
Made on #1333 first (b3726b0), then cherry-picked here. Thanks for the approval. |
|
Fault-injection rerun on 2.0.x with all eight backports at their approved heads ( For this PR:
The unpatched baseline is |



Backport of #1333 to
release/2.0.x. Tracked in #1339.What it fixes: see #1333. The backport changes the same code in the same way.
How it was made: The 2 commits of #1333, no changes. Commits are cherry-picked with
-x, and the changed lines were compared one by one with #1333.Checks: 107
components/coretests pass;admincompiles.Fault-injection run: the same scenarios as #1328 are running on
release/2.0.xwith all the backports. The results will be posted here and in #1339.🤖 Generated with Claude Code