add FanOut recovery: Subscriber.Bounce and consecutive-poll tracking#251
Open
hugowetterberg wants to merge 1 commit into
Open
add FanOut recovery: Subscriber.Bounce and consecutive-poll tracking#251hugowetterberg wants to merge 1 commit into
hugowetterberg wants to merge 1 commit into
Conversation
When a Postgres LISTEN connection goes silently bad — PgBouncer eating the LISTEN re-issue, a network partition that survives the keepalive, etc. — the existing ping-based health check stays green while application notifications stop flowing. Consumers paper over the gap with a fallback poll but have no way to flag that polling is the only thing keeping them caught up, and no way to force a reconnect short of restarting the process. Subscriber.Bounce signals the listen loop to tear down the current connection and reconnect on the next iteration. The channel is buffered to depth 1 so multiple consumers' bounces during one outage coalesce, and the loop drains any pending signal at the start of each fresh connection so stale bounces don't immediately tear down a healthy reconnect. FanOut.EnableRecovery folds the recovery bookkeeping into the FanOut itself: consumers report fallback-poll findings via FanOut.Polled, the FanOut auto-resets the streak inside NotifyWithPayload on each wire-side delivery, and the FanOut bounces the Subscriber once the streak crosses a configurable threshold. The streak counts consecutive non-empty *calls*, not items, so a single backlog-clearing poll on a busy pipeline does not trip the bounce. EnableRecovery registers per- channel poll-saved counter and streak gauge metrics through a MetricsHelper. See docs/fanout-recovery.md for the full pattern and example wiring.
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.
When a Postgres LISTEN connection goes silently bad — PgBouncer eating the LISTEN re-issue, a network partition that survives the keepalive, etc. — the existing ping-based health check stays green while application notifications stop flowing. Consumers paper over the gap with a fallback poll but have no way to flag that polling is the only thing keeping them caught up, and no way to force a reconnect short of restarting the process.
Subscriber.Bounce signals the listen loop to tear down the current connection and reconnect on the next iteration. The channel is buffered to depth 1 so multiple consumers' bounces during one outage coalesce, and the loop drains any pending signal at the start of each fresh connection so stale bounces don't immediately tear down a healthy reconnect.
FanOut.EnableRecovery folds the recovery bookkeeping into the FanOut itself: consumers report fallback-poll findings via FanOut.Polled, the FanOut auto-resets the streak inside NotifyWithPayload on each wire-side delivery, and the FanOut bounces the Subscriber once the streak crosses a configurable threshold. The streak counts consecutive non-empty calls, not items, so a single backlog-clearing poll on a busy pipeline does not trip the bounce. EnableRecovery registers per- channel poll-saved counter and streak gauge metrics through a MetricsHelper.
See docs/fanout-recovery.md for the full pattern and example wiring.