Skip to content

fix(realtime): preserve replacement channels during stale cleanup - #2803

Open
maximilliangrand wants to merge 1 commit into
supabase:masterfrom
maximilliangrand:fix/realtime-stale-channel-cleanup
Open

maximilliangrand wants to merge 1 commit into
supabase:masterfrom
maximilliangrand:fix/realtime-stale-channel-cleanup

Conversation

@maximilliangrand

Copy link
Copy Markdown

🔍 Description

What changed?

Remove a realtime channel by object identity instead of topic. Repeating cleanup on an old channel now leaves a newly subscribed channel with the same topic registered and connected.

Why was this change needed?

An old channel's close callback can run again after its replacement has joined. Filtering by topic removes the replacement from getChannels() and schedules a disconnect, interrupting the active subscription. The underlying Phoenix socket already removes only the specific channel instance.

📸 Screenshots/Examples

The regression joins a channel, unsubscribes it, then joins a replacement with the same topic. Calling either old.unsubscribe() or client.removeChannel(old) again must preserve the replacement. Both cases fail before this fix.

The tests also verify distinct join references, broadcast delivery after the disconnect deadline, and normal disconnection when the replacement is finally removed.

🔄 Breaking changes

  • This PR contains no breaking changes

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format
  • I have run pnpm nx format for the changed files
  • I have added regression tests
  • Documentation: not applicable; no public API changes

📝 Additional notes

Validation on Node 24 and pnpm 11.1.2:

  • Realtime suite: 477 passed, 1 skipped; SDK unit suite: 158 passed.
  • Realtime, SDK, and dependency builds passed. Typechecks passed with --skipSync to bypass a project-reference sync gate; no configuration changes are included.
  • A separate smoke test against the built createClient API passed both cleanup cases using a mock WebSocket server.
  • Formatting and git diff --check passed. Package lint failed; comparing the changed files with the base checkout shows the same 20 source and 3 test diagnostics, with none added by this change.

Live Supabase service integration was not run because Docker is unavailable locally. The SDK unit runner reports disconnect-timeout open handles but exits successfully.

Implementation and independent review were AI-assisted.

@maximilliangrand
maximilliangrand requested review from a team as code owners October 29, 2026 09:00
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 204a3de4-4708-4323-ac58-d32fadf0abc0
Commits

Reviewing files that changed from the base of the PR and between ecab7fb and 0b6b007.

Files selected for processing: 2
  • packages/core/realtime-js/src/RealtimeClient.ts
  • packages/core/realtime-js/test/RealtimeClient.channels.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Removing an unsubscribed channel no longer removes a replacement channel using the same topic. The replacement continues receiving broadcasts, and connection behavior remains correct.

RealtimeClient._remove now removes a channel by object identity instead of topic. Regression tests cover repeated unsubscribe and removal of an old channel after a replacement subscribes to the same topic. They verify the replacement remains registered, receives broadcasts, and prevents a deferred disconnect until it is removed.

Priority: Normal

Change: Bug fix

Merge Risk: Minimal · up to 0b6b0

No actionable merge-blocking risk is established for the channel-cleanup change. It is mergeable subject to normal checks.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

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.

This branch has not been deployed

No deployments
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