Skip to content

fix: wait for pubsub listeners before reconnect#1253

Draft
thlorenz wants to merge 7 commits into
masterfrom
thlorenz/fix-dropped-clients
Draft

fix: wait for pubsub listeners before reconnect#1253
thlorenz wants to merge 7 commits into
masterfrom
thlorenz/fix-dropped-clients

Conversation

@thlorenz
Copy link
Copy Markdown
Collaborator

Summary

Fix pubsub reconnect lifetime safety by ensuring reconnect waits for subscription listener tasks to stop and drop their streams before pooled pubsub clients are replaced.

Details

magicblock-chainlink

This changes the reconnect path from best-effort cancellation to a two-phase drain:

  • account and program subscriptions now track both cancellation and listener-completion signals
  • reconnect drains subscription maps, requests listener shutdown, and waits for listener completion before recreating pooled pubsub clients
  • listener tasks signal completion only after dropping their update stream and running best-effort unsubscribe cleanup
  • explicit account unsubscribe remains fast by only cancelling the listener and leaving the subscription entry visible until listener cleanup, so a near-simultaneous reconnect can still wait for completion

The pubsub pool reconnect docs now call out the required precondition that old listener streams must be finished before pooled clients are dropped.

Additional tests cover successful account/program listener drain, completion timeout behavior, and the fast explicit-unsubscribe path preserving the map entry for reconnect drain.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Warning

Review limit reached

@thlorenz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 22 minutes and 8 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c863ab45-e380-4897-9f7c-9e0a5e5031a9

📥 Commits

Reviewing files that changed from the base of the PR and between 4ba4a87 and 971bdb0.

📒 Files selected for processing (3)
  • magicblock-chainlink/src/remote_account_provider/chain_pubsub_actor.rs
  • magicblock-chainlink/src/remote_account_provider/pubsub_common.rs
  • magicblock-chainlink/src/remote_account_provider/pubsub_connection_pool.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch thlorenz/fix-dropped-clients

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 and usage tips.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant