Repository navigation
Conversation
The native transport connected through IOWebSocketChannel.connect, which uses WebSocket.connect and discards the HTTP response when the upgrade is rejected with a non-101 status. That hid the server's error body, so an invalid apikey surfaced only as "HTTP status code: 401/403". Drive the upgrade with HttpClient instead: on a successful 101 the socket is detached and wrapped in an IOWebSocketChannel exactly as before, and on a rejected upgrade the response body and sb-error-code header are parsed into a new RealtimeConnectException (statusCode, message, hint, errorCode) in the same request, without a follow-up round trip. The browser WebSocket API exposes neither the status nor the body of a failed upgrade, so the web transport is unchanged and RealtimeConnectException is native-only.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe realtime client now exposes Sequence Diagram(s)sequenceDiagram
participant RealtimeClient
participant WebSocketEndpoint
participant HTTPEndpoint
RealtimeClient->>WebSocketEndpoint: Attempt WebSocket connection
WebSocketEndpoint-->>RealtimeClient: Return upgrade failure
RealtimeClient->>HTTPEndpoint: Fetch mapped HTTP error response
HTTPEndpoint-->>RealtimeClient: Return status and error details
RealtimeClient-->>RealtimeClient: Emit RealtimeConnectException
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Checkov (3.3.8)sdk-compliance.yamlTraceback (most recent call last): 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. Comment |
…l handshake Replace the native-only manual handshake with a cross-platform approach: keep the standard WebSocket transport untouched, and when the upgrade is rejected, re-request the same endpoint over HTTP to recover the server's error body. The WebSocket API discards the handshake response (status only on native, nothing on web), but a plain follow-up GET returns the same response, so the message, hint and sb-error-code are surfaced as a RealtimeConnectException on both native and web. Reverts the manual HttpClient handshake and the crypto dependency added in the previous commit.
…ymbols Add a const constructor to satisfy the prefer-declaring-const-constructor DCM rule, and register RealtimeConnectException and its members in sdk-compliance.yaml under realtime.client.connect so the capability matrix symbol check passes.
## What Adds a repo-level `.coderabbit.yaml` that disables CodeRabbit's failing commit status: ```yaml reviews: commit_status: true fail_commit_status: false ``` ## Why Open PRs are currently showing a red `CodeRabbit` check with the reason **"Review rate limited"** (e.g. #1630, #1629, #1627), even though nothing is actually wrong with the change. A completed review shows `pass` (e.g. #1626). - `commit_status: true` keeps the useful passing check for completed reviews. - `fail_commit_status: false` stops CodeRabbit from setting a `failure` status when it can't review (which is what the rate-limit case triggers). Committing the config overrides CodeRabbit's cloud/org defaults. ## Note If a rate-limited PR still goes red after this lands, the rate-limit failure path ignores this flag and the only remaining lever is `commit_status: false` (disables the check entirely, losing the green pass too).
|
In its current implementation it retries for every kind of exception, but I think we should make this retry more specific. The example in your issue description is a WebSocketChannelException, which exposes an
This would also be a breaking change as the previous exception is no longer thrown. So I would check whether we can extend the WebSocketException to be compatible with existing exception checks. |
Hmm, after further research I think we should just close this one, the native users will already be able to get the status code and that ought to be enough for them to figure out what is wrong. Users on web don't get any information, even if we keep the GET, and there is nothing we can do about that due to the underlying that the browser's WebSocket API deliberately hides it. We should really fix a list of exceptions we shouldn't retry though, but that's a separate issue. |
## What Adds a repo-level `.coderabbit.yaml` that disables CodeRabbit's failing commit status: ```yaml reviews: commit_status: true fail_commit_status: false ``` ## Why Open PRs are currently showing a red `CodeRabbit` check with the reason **"Review rate limited"** (e.g. #1630, #1629, #1627), even though nothing is actually wrong with the change. A completed review shows `pass` (e.g. #1626). - `commit_status: true` keeps the useful passing check for completed reviews. - `fail_commit_status: false` stops CodeRabbit from setting a `failure` status when it can't review (which is what the rate-limit case triggers). Committing the config overrides CodeRabbit's cloud/org defaults. ## Note If a rate-limited PR still goes red after this lands, the rate-limit failure path ignores this flag and the only remaining lever is `commit_status: false` (disables the check entirely, losing the green pass too).
Summary
When the Realtime server rejects the WebSocket upgrade, for example on a missing or invalid
apikey, the client previously surfaced only a bare status code buried in aWebSocketChannelException:The server returns a helpful body, but the WebSocket handshake discards it (only the status is visible on native, nothing at all on web). This PR recovers that information and surfaces it as a new
RealtimeConnectExceptionon both native and web:What changed
RealtimeClient: whenWebSocketChannel.readyfails, a new_fetchConnectionErrorhelper re-requests the same endpoint over HTTP to recover the server's error response, then surfaces it through the existingonErrorandsubscribeerror paths.RealtimeConnectException(statusCode,message,hint,errorCode), exported from the package barrel.test/invalid_apikey_test.dartasserting an invalid apikey yields aRealtimeConnectException.How it works
On a failed upgrade,
_fetchConnectionErrorissues a plainGETto the same endpoint (scheme mappedws/wsstohttp/https, with the apikey already present in the query). A non-2xx response is parsed intoRealtimeConnectException(statusCode, message, hint, errorCode), readingmessage/hintfrom a JSON body and the code from thesb-error-codeheader. On a 2xx response or an unreachable server it falls back to the original error. The request reuses the injectedhttpClientwhen provided, otherwise a short-lived client with a 5 second timeout.The standard WebSocket transport is left untouched, so this works identically on native and web with no new dependency and no reimplementation of the WebSocket handshake.
Testing
test/invalid_apikey_test.dart(integration): an invalid apikey yields aRealtimeConnectExceptionwith a 401 or 403 status.realtime_integration_test.dartsuite passes for both protocol versions (subscribe, broadcast, presence, postgres changes, heartbeats), plussocket_test,mock_test, andwebsocket_io_test.message,hint, andsb-error-codeare surfaced as shown above.Commit history
The first commit implements a native-only alternative that reads the body during a manual
HttpClienthandshake. The second commit reverts it in favor of the cross-platform follow-up fetch, which is the net content of this PR. The first commit is kept only so the two approaches can be compared, and can be squashed away on merge.Open items
RealtimeConnectExceptionis a new public symbol; thesdk-compliance.yamlcheck needs a canonical capability ID fromsupabase/sdkto register it against.