Repository navigation
fix(realtime): port main's changes to v3 - #1798
Conversation
|
The following capabilities are marked
The following capabilities are marked
These may have been renamed, removed, or never registered. Please update the capability matrix. |
grdsdev
left a comment
There was a problem hiding this comment.
Review notes below. Three findings are on lines outside the diff, so they are here:
client.py:287 — a second remove_all_channels() raises ValueError. unsubscribe() now removes the channel from self.channels. A second call (or a call with no channels) builds an empty task list, and asyncio.wait([]) raises ValueError: Set of Tasks/Futures is empty. Before this PR, the second call only resent leave. set_auth already guards this case with if tasks:.
client.py:135 — ConnectionClosed skips the backoff. The 60 s cap applies only to the TimeoutError/OSError path. except websockets.ConnectionClosed: continue reconnects at once, and retries resets on each successful connect. If the server accepts and then closes at once (bad apikey, overload), the client spins in a tight connect/close loop. Suggest that this path also goes through exponential_delay.
client.py:354 — endpoint_url() repeats the old query logic. It still uses with_query(**self.url.query, vsn=VSN), the pattern this PR replaced in normalize_url. Nothing in src calls it. Suggest deleting it, or making it call normalize_url(self.url, self.last_token).
de2c215 to
ba1a9de
Compare
ba1a9de to
59efdb1
Compare
59efdb1 to
afc0afe
Compare
079980b to
d4624e0
Compare
d4624e0 to
5ec771c
Compare
cabd69e to
a5f04cf
Compare
6541e1d to
fe04801
Compare
fe04801 to
9f5e02a
Compare
33db9d8 to
9efaadd
Compare
9efaadd to
a14928d
Compare
(cherry picked from commit 80688d1)
(cherry picked from commit 8913406)
(cherry picked from commit 954403b)
…#1673) Co-authored-by: breken-ai <[email protected]> (cherry picked from commit df4ed51)
(cherry picked from commit a2a142e)
(cherry picked from commit 23ddbca)
…treams on leave The server does not reply to access_token, so set_auth() now sends it without waiting and the test mock no longer acks it. joined is derived from state, unsubscribe() delivers a close message to the messages iterator, channel() warns when it ignores different options, remove_channel() only unsubscribes the given channel, remove_all_channels() can run twice, a closed connection backs off before reconnecting, endpoint_url() uses normalize_url(), and the README examples added here use the v3 API.
…on reconnect subscribe() registers the channel again and clears stale messages, so the same object can be resubscribed after unsubscribe(), and it no longer writes the token into shared options. unsubscribe() deregisters before leaving, so the iterator gets one close message instead of two. automatically_reconnect() applies the backoff and max_retries to closed connections as well, resets the retry count only after a connection has been healthy for a minute, and also reconnects on asyncio.TimeoutError, which differs from TimeoutError on Python 3.10. Failures while unsubscribing all channels or sending a new token are logged instead of left unretrieved, and the README documents the v3 API throughout.
joined is now a property derived from the channel state, so it is a public symbol of RealtimeChannel.
a14928d to
89a38b6
Compare
## Why Concurrent initial channel subscriptions can open two WebSockets on one client. The second assignment loses the first socket, which remains alive after `close()`. Closes #1852. ## What changed - Serialize the opening handshake and recheck the connection under a lazy client lock. - Add a real localhost WebSocket regression for concurrent subscriptions, a sequential control, cancellation, and failed-handshake retry. ## Scope This covers initial connection ownership in the current Realtime API. Reconnect policy and the v3 lifecycle rewrite in #1798 remain separate. Legacy [realtime-py#290](supabase/realtime-py#290) handles background-task cancellation rather than duplicate handshakes. ## Tradeoffs Create the lock inside `connect()` so clients constructed before `asyncio.run()` work on Python 3.9. Keep buffered-send setup outside the lock because it can trigger a reconnect. ## Blast radius Only the async Realtime client changes. No public signatures, dependencies, or retry settings change. ## Verification - New tests on untouched upstream fail twice with two sockets and one orphan. The fix passes all four tests, including on Python 3.9. The public wire reproduction now reports one socket and none after close. - No-service package selection passes 28 tests. Existing AsyncPush teardown diagnostics also occur on upstream. Mypy, Ruff, format, `make ruff`, wheel and sdist build, and `git diff --check` pass. - Full Supabase service tests are unverified. Isolated CLI startup fails before services start because Docker image blobs return input/output errors. AI-assisted contribution. Reproductions and checks were run locally. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Concurrent connection attempts now share a single WebSocket connection, preventing duplicate connections during startup. * Cancelling a waiting connection attempt no longer interrupts the connection in progress. Failed handshakes can be retried, and connection attempts remain reliable across event loops. * **Tests** * Added coverage for concurrent startup, cancellation, retry after a failed handshake, and connections across separate event loops. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Lukas Klingsbo <[email protected]>
…ssions (#2114) Step 5 of SDK-2765, port of supabase-flutter #1797 and #1798. Closes SDK-2988. - `json_text()`, `json_text_at()`, `json_object()`, `json_object_at()` on JSON columns return a `JsonPath`, which filters, orders and has `is_null()`. Operands of a `->` path are sent as JSON. - `cast(sql_type, value_type)`, `sum()`, `avg()`, `min()`, `max()`, `count()` and `DerivedExpression.count_all()` return a select-only `DerivedExpression`, so filtering or ordering on one is a type error. A cast of a cast and an aggregate of an aggregate raise `ValueError`. - `select_only()` takes any `Expression`. JSON paths and derived expressions are aliased to their own expression (shortened past 63 bytes like Dart) and `PartialRow` reads them by `response_key`. `min()`/`max()` decode as the column, `sum()` without its `Field` constraints, `avg()` as `Decimal` over `Decimal`. - The select list cleaner no longer strips whitespace after an escaped quote inside a quoted alias. - Test stack enables `db_aggregates_enabled`. Integration tests cover each new expression.
Cherry-picks main's realtime commits onto v3's overhauled client.
test_join_ref.py.subscribe()andunsubscribe()wait for the reply, and callers bound them withasyncio.wait_for."*"broadcast listeners, ignoring case): v3 has no broadcast callbacks.channel.messagesyields every broadcast without filtering by event.Review fixes
access_token, soset_auth()sends it without waiting. The test mock no longer acks it, and the rejoin test leaves before joining again.joinedis derived fromstate, andunsubscribe()delivers a close message to themessagesiterator.channel()warns when it ignores different options for an existing topic, andremove_channel()only unsubscribes the channel it is given.remove_all_channels()can run twice, a closed connection backs off before reconnecting, andendpoint_url()usesnormalize_url().unsubscribe().subscribe()registers it again, clears stale messages and no longer writes the token into shared options.unsubscribe()delivers exactly one close message.automatically_reconnect()applies the backoff andmax_retriesto dropped connections too, resets the count after a minute of healthy connection, and reconnects onasyncio.TimeoutErroron Python 3.10.Commits
Stack
This replaces #1789: main's changes since 6f522d3 are cherry-picked onto v3 one package at a time, so each part can be reviewed on its own. Merge from the bottom up.