fix(#4961): PostgresqlListenWakeup falls back to a timeout wait when the DB is unreachable#4965
Merged
jeremydmiller merged 1 commit intoJul 17, 2026
Conversation
…the database is unreachable WaitAsync now guards ensureListeningAsync: OperationCanceledException still propagates (shutdown), but any other exception — a dropped/unreachable database during a restart, failover, or maintenance window — is logged at Warning and falls back to a plain Task.Delay(timeout) instead of escaping. The HighWaterAgent poll loop awaits the wakeup outside any try/catch, so an unguarded throw here permanently froze all projection progress until the process was restarted (marten#4961). receiveLoop already nulls _connection, so the next call retries the LISTEN and self-heals once the database returns. This is the Marten-side mitigation and ships independently of JasperFx (per the #4961 hand-off): defect B is the only place that throws a connection error into the unguarded high-water loop. The upstream defense-in-depth (#524, defects A + C, in JasperFx 2.28.0) is a separate follow-up — the 2.27.0 -> 2.28.0 bump is deferred because it currently regresses Marten's binary-COPY rebuild (rebuild_with_bulk_copy_inserts, 23505 duplicate key), which is being handled as its own task alongside the rebuild-optimization work. Adds a deterministic repro: wait_async_falls_back_to_timeout_when_the_database_is_unreachable points the wakeup at an unreachable port and asserts WaitAsync does not throw and returns promptly. All 4 tests in the file pass (net10.0). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XKKBPsFJ83jd2o4hyGJnj6
jeremydmiller
force-pushed
the
fix/4961-listen-notify-highwater-resilience
branch
from
July 17, 2026 18:28
9fc08c2 to
aa93f2a
Compare
This was referenced Jul 18, 2026
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.
Closes #4961 (Marten-side mitigation — ships independently of JasperFx).
The bug
When
UseListenNotifyForEventAppends = true, a brief DB outage (restart / failover / maintenance) could permanently freeze all projection progress until the process was restarted:PostgresqlListenWakeup.WaitAsync→ensureListeningAsync→OpenConnectionAsyncthrows when the DB is unreachable, and theHighWaterAgentpoll loop awaits the wakeup outside any try/catch, so that throw ended the high-water loop.This PR
WaitAsyncnow guardsensureListeningAsync:OperationCanceledExceptionstill propagates (shutdown); any other exception is logged at Warning and falls back toTask.Delay(timeout).receiveLoopalready nulls_connection, so the next call retries the LISTEN and self-heals once the DB returns. Defect B is the only place that throws a connection error into the unguarded loop, so this resolves the reported symptom on its own.Deterministic repro
wait_async_falls_back_to_timeout_when_the_database_is_unreachable(unreachable port) assertsWaitAsyncdoesn't throw and returns promptly. All 4 tests in the file pass (net10.0).Follow-up (separate task)
The upstream defense-in-depth (#524, defects A + C —
HighWaterAgentguards everyIDaemonWakeup.WaitAsyncand the watchdog observes the real loop task) ships in JasperFx 2.28.0. The2.27.0 → 2.28.0bump is deferred to its own PR because it currently regresses Marten's binary-COPY rebuild (rebuild_with_bulk_copy_inserts→23505duplicate key) — that integration is being handled alongside the rebuild-optimization work.🤖 Generated with Claude Code