|
Ran
|
Files
22
|
Run time
0s
|
Badge
README BADGES
|
push
github
fix(realtime): forget channels in remove_all_channels (#1925) ## What `AsyncRealtimeClient.remove_all_channels()` sent `phx_leave` for every channel and closed the socket, but never removed the channels from `self.channels`. The socket closes right away, so the leave replies that would normally drop them never arrive, and `get_channels()` kept returning every "removed" channel. On top of that, it iterated `self.channels.items()` directly, so a leave reply processed mid-removal (`on_close` → `_remove_channel`) raised `RuntimeError: dictionary changed size during iteration`. Fixes SDK-1674. Also reported as #1678 (SDK-1970). ## Changes - `remove_all_channels()` now loops over a snapshot of the channels, unsubscribes each one, and removes it with `_remove_channel` (the same path `remove_channel()` uses). If an unsubscribe raises, the loop still removes every channel and closes the socket, then re-raises the first error. - Leaves are sent one at a time rather than concurrently like realtime-js. If the connection drops during removal, concurrent sends would each start their own reconnect, and `connect()` has no guard against that. Sending sequentially keeps it to one. - New `tests/test_remove_all_channels.py`, with no live server: a fake connection patched into `realtime._async.client.connect` records sent messages and can answer leaves with a `phx_reply`. Covers an empty `get_channels()` afterwards, a leave per channel, the socket being closed, a fresh channel for a reused topic, leave replies arriving during removal, and removal continuing past an unsubscribe that raises. All four tests fail on `main`. ## realtime-js behaviour #1678 was closed because realtime-js supposedly doesn't clear its channels either. It does, though not with a literal `this.channels = []`. `removeAllChannels()` in [`packages/core/realtime-js/src/RealtimeClient.ts`](https://github.com/supabase/supabase-js/blob/ecab7fb69/packages/core/realtime-... (continued)
853 of 880 relevant lines covered (96.93%)
0.97 hits per line
| Coverage | ∆ | File | Lines | Relevant | Covered | Missed | Hits/Line |
|---|