Repository navigation
fix: don't let stale syncing flags stall mempool tx processing - #1165
Merged
Merged
Conversation
At startup the mempool handler waits in waitForSyncing until its addresses' `syncing` flag clears. That wait had no timeout and only checked `initializing` on entry, and syncAddresses never cleared the flag for addresses it hadn't reached when it failed. A sync that died left addresses flagged, so a tx to one of them arriving during startup waited forever; two such handlers (MAX_MEMPOOL_TXS_TO_PROCESS_AT_A_TIME) stalled all mempool processing, delaying triggers to block time and leaving client payments pending until restart. - waitForSyncing stops waiting once initialization ends or after CHRONIK_SYNCING_WAIT_TIMEOUT_MS (2 min), logging the addresses still flagged. Proceeding is safe: the live upsert and the bulk createMany (skipDuplicates) both tolerate the other inserting first. - syncAddresses clears the flag in a finally for every address it didn't release, so a failed sync no longer leaves addresses flagged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019G564fZdU5yXdFx9sELPdd
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 18 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
New payments that arrive while the app is starting up could get stuck waiting forever. When that happened, every later unconfirmed payment queued behind them until the next restart. Triggers then fired late, when the payment confirmed in a block, and client payments stayed pending.
Why: At startup, the mempool handler waits (
waitForSyncing) until each of its addresses'syncingflag clears. That wait had no timeout and only checkedinitializingonce, on entry.syncAddressesalso never cleared the flag for addresses it hadn't reached when it failed, so a sync that crashed or was redeployed left addresses flagged indefinitely. A payment to one of those addresses during startup therefore waited forever. OnlyMAX_MEMPOOL_TXS_TO_PROCESS_AT_A_TIME(2) mempool payments run at once, so two stuck handlers stalled all mempool processing.Changes:
waitForSyncingstops waiting once initialization finishes or afterCHRONIK_SYNCING_WAIT_TIMEOUT_MS(2 min), and logs the addresses still flagged. Proceeding is safe: the liveupsertTransactionand the bulkcreateMany(skipDuplicates) both handle the other path inserting first, and after startup the handler already skips this wait.syncAddressesclearssyncingin afinallyfor every address it didn't release, so a failed sync no longer leaves addresses flagged. A failure to clear is logged and doesn't throw.This doesn't cover a process killed mid-sync; the new timeout handles that case.
Test plan
tests/unittests/chronikService.test.ts(stale syncing flags):waitForSyncinggives up after the timeout when an address stays flagged.syncAddressesclears the flag only for addresses it didn't finish when the sync throws, and makes no extra clear call when every address finished.chronikService.test.tspasses (145 tests). Lint is clean on the changed files.tscreports the same errors asmaster, all in other test files.paybutton-config.jsonand the docker test setup./adminSync Status section: the count of addresses flagged as syncing should drop to 0 once the startup sync ends.Generated by Claude Code