Skip to content

fix: don't let stale syncing flags stall mempool tx processing - #1165

Merged
Klakurka merged 1 commit into
masterfrom
claude/serene-turing-e0fk7y
Nov 26, 2026
Merged

Klakurka merged 1 commit into
masterfrom
claude/serene-turing-e0fk7y

Conversation

@Klakurka

Copy link
Copy Markdown
Member

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' syncing flag clears. That wait had no timeout and only checked initializing once, on entry. syncAddresses also 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. Only MAX_MEMPOOL_TXS_TO_PROCESS_AT_A_TIME (2) mempool payments run at once, so two stuck handlers stalled all mempool processing.

Changes:

  • waitForSyncing stops waiting once initialization finishes or after CHRONIK_SYNCING_WAIT_TIMEOUT_MS (2 min), and logs the addresses still flagged. Proceeding is safe: the live upsertTransaction and the bulk createMany (skipDuplicates) both handle the other path inserting first, and after startup the handler already skips this wait.
  • syncAddresses clears syncing in a finally for 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

  • New unit tests in tests/unittests/chronikService.test.ts (stale syncing flags):
    • waitForSyncing gives up after the timeout when an address stays flagged.
    • It stops waiting as soon as the client finishes initializing.
    • It returns right away when the addresses aren't syncing, and doesn't wait when not initializing.
    • syncAddresses clears 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.ts passes (145 tests). Lint is clean on the changed files.
  • tsc reports the same errors as master, all in other test files.
  • Not run here: suites that need paybutton-config.json and the docker test setup.
  • After deploying, check the /admin Sync Status section: the count of addresses flagged as syncing should drop to 0 once the startup sync ends.

Generated by Claude Code

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
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f72d8c0b-5983-4759-aa58-ddb72f5ce3b7
Commits

Reviewing files that changed from the base of the PR and between d5157bd and d829be9.

Files selected for processing: 3

  • constants/index.ts
  • services/chronikService.ts
  • tests/unittests/chronikService.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@Klakurka Klakurka self-assigned this Nov 26, 2026
@Klakurka Klakurka added the bug Something isn't working label Nov 26, 2026
@Klakurka
Klakurka merged commit e640f5e into master Nov 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants