← Back to Pull requests

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

Merged
dhruva4869 merged 2 files (151 lines) on Nov 11, 2026 05:07 UTC
View on GitHub
dhruva4869 dhruva4869 commented on Nov 06, 2026 07:43 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.

    Original commit: 08068000a6f11f47ef91de2ca9a0b3542db5b947 / #35400

    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.

    ---------

    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

    Diff: 151 lines (+150 / -1) across 2 files Reviewer: arpang Review duration: 7044m
    All Vouch review confidence checks passed
    Residual risk 0.12 = Change Risk (0.35) × (1 − Review Confidence (0.66)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.35 · 151 lines diff across 2 files
    0.35
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.54 · 1 substantive comment(s)
    0.54
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    66%
    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.301
    Real PR Conversation Timeline
    4 items
    yugabyte-ci yugabyte-ci commented on Nov 06, 2026 07:43 UTC
    Contributor

    <!-- Reviewable:start -->
    This change is <img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>
    <!-- Reviewable:end -->

    arpang arpang approved these changes on Nov 06, 2026 07:52 UTC
    Approved Reviewer

    Approved these changes.

    arpang arpang approved these changes on Nov 06, 2026 07:55 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    dhruva4869 dhruva4869
    Labels
    risk: low confidence: 66.3% 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: 34.5% (LOW) · Higher = larger blast radius
    34.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: 66.3% · Lower = rushed or shallow review
    66.3%
    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: 11.6% · Safe to merge
    11.6%