Skip to content

fix(realtime): prevent silent Postgres connection drop on notification listener (fixes #2619) - #2841

Merged
krushit1307 merged 3 commits into
krushit1307:mainfrom
Diwakar-odds:fix/issue-2619-pg-listener-drop
Aug 11, 2026
Merged

fix(realtime): prevent silent Postgres connection drop on notification listener (fixes #2619)#2841
krushit1307 merged 3 commits into
krushit1307:mainfrom
Diwakar-odds:fix/issue-2619-pg-listener-drop

Conversation

@Diwakar-odds

@Diwakar-odds Diwakar-odds commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixed a severe bug where the Postgres NOTIFY listener stream would silently drop connections because the connection handler task would only poll a single message and immediately terminate.

Motivation

Closes #2619.
The connection task in services/realtime-proxy/src/listener.rs was incorrectly implemented using futures_util::future::poll_fn(|cx| connection.poll_message(cx)).await. This caused the spawned stream_task to exit after resolving a single poll, effectively dropping the underlying Postgres connection and breaking all real-time events for the application.

By replacing the single poll_fn with a continuous .await on the connection driver (connection.await), the task correctly maintains the connection lifecycle until it is explicitly aborted or an error occurs.

Changes

  • services/realtime-proxy/src/listener.rs:
    • Modified the spawned background connection task to await the entire connection (connection.await) instead of polling for a single message.

Acceptance Criteria

  • Await the connection driver continuously inside the spawn block using if let Err(e) = connection.await.
  • Fix the silent Postgres connection drop issue in the real-time proxy.

Impact & Side Effects

The listener now robustly maintains long-lived Postgres NOTIFY connections without prematurely dropping. No breaking changes or side effects.

Summary by CodeRabbit

  • Bug Fixes
    • Improved PostgreSQL connection handling for greater reliability.
    • Preserved existing real-time listener behavior.

@github-actions github-actions Bot added bug Something isn't working database ECSoC26 Elite Coders Summer Of Code'26 - Open Source Program labels Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bd27bc6e-74ba-427f-b933-6a2912de05fc

📥 Commits

Reviewing files that changed from the base of the PR and between dcc53ba and b7fa293.

📒 Files selected for processing (1)
  • services/realtime-proxy/src/listener.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • services/realtime-proxy/src/listener.rs

📝 Walkthrough

Walkthrough

The PostgreSQL connection task now awaits the connection future directly. This replaces single-message polling and keeps the notification connection active.

Changes

PostgreSQL notification listener

Layer / File(s) Summary
Continuous connection driving
services/realtime-proxy/src/listener.rs
The spawned task awaits connection directly instead of using poll_fn and poll_message.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the realtime Postgres notification listener fix and matches the main change.
Linked Issues check ✅ Passed The change directly implements issue #2619 by awaiting the Postgres connection driver instead of polling one message.
Out of Scope Changes check ✅ Passed The one-line change is limited to the listener behavior required by issue #2619.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@Diwakar-odds

Copy link
Copy Markdown
Contributor Author

Hi maintainers, the real-time Postgres listener bug is fixed!

This PR directly involves Core Backend Logic Changes / Concurrency & Reliability:

  1. Fixed the underlying connection task for the real-time proxy that was silently exiting due to the incorrect usage of futures_util::future::poll_fn in the tokio::spawn block.
  2. By replacing it with a continuous .await (connection.await), the Postgres connection driver now correctly stays alive to poll and handle background NOTIFY events as long as the application requires.

This is a core reliability/database fix that prevents the real-time infrastructure from fatally failing. As such, it satisfies the L3 criteria for ECSoC. Could you please review and apply the Level 3 and good-backend labels for Sentinel XP? Thank you!

@krushit1307

Copy link
Copy Markdown
Owner

@Diwakar-odds it looks like this PR has some merge conflicts; mind resolving them so we can get it merged? 🚀

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/graphql-client.ts`:
- Around line 116-122: Define a single partial-response contract that preserves
both partial data and GraphQL errors, then apply it consistently: update
fetchGraphQL in src/lib/graphql-client.ts (lines 116-122) to expose the selected
signal, adapt useCursorEventsQuery in src/hooks/useCursorEventsQuery.ts (lines
111-115) and the warning handling in src/routes/admin.users.tsx (lines 131-136),
and update the corresponding expectations in src/lib/graphql-client.test.ts
(lines 56-71) and src/hooks/useCursorEventsQuery.test.ts (lines 81-111).
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e086ce80-d300-4708-8999-aa9b4e1c40b8

📥 Commits

Reviewing files that changed from the base of the PR and between e1f5178 and 5999a65.

📒 Files selected for processing (6)
  • services/realtime-proxy/src/listener.rs
  • src/hooks/useCursorEventsQuery.test.ts
  • src/hooks/useCursorEventsQuery.ts
  • src/lib/graphql-client.test.ts
  • src/lib/graphql-client.ts
  • src/routes/admin.users.tsx

Comment thread src/lib/graphql-client.ts
Comment on lines +116 to +122
// ── Partial failure: data exists alongside errors ─────────────
if (json.errors && json.errors.length > 0 && json.data) {
reportPartialErrors(json.errors);
// Return the partial data — callers can inspect the error via
// the thrown GraphQLPartialError if needed, but the default
// behaviour is to surface partial data gracefully.
return json.data;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Define one partial-response contract and apply it to every consumer.

fetchGraphQL returns partial data at src/lib/graphql-client.ts lines 116-122. Its documentation says it throws GraphQLPartialError, and src/routes/admin.users.tsx catches that error. The route warning branch is therefore unreachable. Select one contract that preserves both partial data and GraphQL errors, then update all consumers and tests.

  • src/lib/graphql-client.ts#L116-L122: expose GraphQL errors with partial data through the selected contract.
  • src/hooks/useCursorEventsQuery.ts#L111-L115: preserve cursor-query partial-data behavior under the selected contract.
  • src/routes/admin.users.tsx#L131-L136: handle the selected partial-response signal and show the warning.
  • src/lib/graphql-client.test.ts#L56-L71: assert the selected client contract instead of data-only resolution.
  • src/hooks/useCursorEventsQuery.test.ts#L81-L111: assert the cursor consumer behavior for the selected contract.
📍 Affects 5 files
  • src/lib/graphql-client.ts#L116-L122 (this comment)
  • src/hooks/useCursorEventsQuery.ts#L111-L115
  • src/routes/admin.users.tsx#L131-L136
  • src/lib/graphql-client.test.ts#L56-L71
  • src/hooks/useCursorEventsQuery.test.ts#L81-L111
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/graphql-client.ts` around lines 116 - 122, Define a single
partial-response contract that preserves both partial data and GraphQL errors,
then apply it consistently: update fetchGraphQL in src/lib/graphql-client.ts
(lines 116-122) to expose the selected signal, adapt useCursorEventsQuery in
src/hooks/useCursorEventsQuery.ts (lines 111-115) and the warning handling in
src/routes/admin.users.tsx (lines 131-136), and update the corresponding
expectations in src/lib/graphql-client.test.ts (lines 56-71) and
src/hooks/useCursorEventsQuery.test.ts (lines 81-111).

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@krushit1307
krushit1307 merged commit ee9ab4f into krushit1307:main Aug 11, 2026
3 of 4 checks passed
@Diwakar-odds

Copy link
Copy Markdown
Contributor Author

Hi @krushit1307, I noticed this PR was merged/closed but seems to be missing the good pr and good backend labels (as this involved backend work). Could you please take a look and add the appropriate labels if it qualifies? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working database ECSoC26-L1 ECSoC26 Elite Coders Summer Of Code'26 - Open Source Program

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(realtime): prevent silent Postgres connection drop on notification listener

2 participants