← Back to Pull requests

[#35386] YSQL: Fix lost notifications after the only listener on a node re-LISTENs #35400

Closed
unknown closed this pull request without merging on Nov 03, 2026 09:17 UTC
View on GitHub
unknown unknown commented on Oct 19, 2026 10:45 UTC
Author

Summary


When the only listener on a node UNLISTENs and the same backend LISTENs again, the notifications of the next transaction are lost.

Each listening backend keeps ybListenerQueueScanCurrentXactState to skip queue entries that the notifications poller writes twice when it replays an unacknowledged transaction. A BEGIN marker with the same xid as the previous one is treated as a replay. These xids come from the notifications slot's virtual WAL, so they are only unique within one slot and cannot be compared across slots: numbering restarts every time the slot is created, which happens when a node gets its first listener after the last one left. The state was never reset, so the first transaction on a new slot could match the last transaction the backend saw on the old slot (in the issue's repro both are xid 2), and its notifications were skipped as duplicates.

The fix ties the state to the slot its xids came from, identified by the existing poller_id: it changes exactly when the slot is recreated and is kept across a poller's crash restarts.

  • The scan state records the poller_id it was built under. Exec_ListenPreCommit resets the state when the backend registers under a different poller, whether this backend recreated the slot or another one did.

  • When the poller is unchanged because another backend kept it alive, the state is kept, so a crash replay of a transaction the backend already received is still skipped.

  • Clear the leftover skip count when a new transaction starts, so a skip count left over from one transaction cannot drop notifications from the next.
  • The other way to get the same false duplicate, an old poller writing to the queue after a new listener registered, is already prevented by the existing poller_id check on the queue write path.

    Test plan


  • testNotifyAfterSoloListenerRelistens. Without the fix it fails 3/3 with expected:<[n2a, n2b, n3]> but was:<[n3]>, and the listener logs Listener found duplicate txn BEGIN entry in async queue (xid 2), skipping 2 notifications.

  • testNotifyAfterRelistenOnSlotRecreatedByAnotherListener

  • testNoDuplicateAfterRelistenWithSamePoller

  • testListenNotifyNoDuplicateAfterPollerCrashBeforeAck (existing replay test)
  • ./yb_build.sh debug --java-test 'org.yb.pgsql.TestPgListenNotify#testNotifyAfterSoloListenerRelistens'
    ./yb_build.sh debug --java-test 'org.yb.pgsql.TestPgListenNotify#testNotifyAfterRelistenOnSlotRecreatedByAnotherListener'
    ./yb_build.sh debug --java-test 'org.yb.pgsql.TestPgListenNotify#testNoDuplicateAfterRelistenWithSamePoller'
    ./yb_build.sh debug --java-test 'org.yb.pgsql.TestPgListenNotify#testListenNotifyNoDuplicateAfterPollerCrashBeforeAck'
    

    Checked items were run on a debug build on macOS arm64, against an earlier revision of this PR.

    Diff: 351 lines (+263 / -88) across 4 files Reviewer: arpang Review duration: 21512m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 351 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.351
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #35400"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.5% (MEDIUM) · Higher = larger blast radius
    42.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%