supabase-js: WebSocket connection failed on subscribing to realtime channel
Bug report
Describe the bug
I’m trying to use Supabase’s realtime updates locally, and I’m getting the following error
WebSocket connection to 'ws://localhost:54321/realtime/v1/websocket?apikey=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0&vsn=1.0.0' failed
To Reproduce
- Clone this repo https://github.com/skulltech/sample-realtime-app
- Run
yarn installandsupabase start, and thenyarn devto start the server. - Go to
http://localhost:3000and check the console to see the above mentioned error. - The webapp has some basic functionality for writing and reading to database to make sure that the other Supabase functionalities are working as expected.
Expected behavior
No errors while subscribing to the realtime channel.
Screenshots
System information
- OS: macOS
- Browser: Chrome
- Version of supabase-js: 2.2.3
- Version of Node.js: v19.4.0
- Version of Supabase CLI: 1.29.2
- Version of Docker desktop for Mac: 4.15.0
Additional context
The same code seems to be working on production Supabase at app.supabase.com.
The same code was working before I updated my whole stack, i.e. updated Supabase CLI as well as @supabase/supabase-js, moved to Postgres v15 locally (i.e. in config.toml), from v14 previously, and ran brew upgrade which included updating docker desktop.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 16
- Comments: 42 (1 by maintainers)
I am having the same issue.
Fixed in
"@supabase/supabase-js": "2.4.0"@skulltech @aerophobicI continue to have this issue after running
brew upgrade supabasefollowed bysupabase stopandsupabase start.Testing with:
@atanaskanchev I am having the same issues and I am using “@supabase/supabase-js”: “2.4.0”.
If you have it behind nginx, make sure to enable
upstream websocketrule in configuration also the headersThis fixed for me.
Was also experiencing the same issue and restarted supabase a dozen times. What finally fixed it was clearing out all the local/session storage and cookies from the browser.
For anyone having the same issue, what @DavidMelnychuk mentioned seems to solve the problem. At least it did for me.
I am running 2 separate supabase local instances (each with its own ports and project_id. Every time I switch to a project (to work on development), I need to remove the cache, and cookies from the browser, as it uses the cookies from the last used supabase instance.
Hope it helps!
^ This is the only thing that solved it for me locally
I had the wrong anon key, updating the key found by running
npx supabase statusfixed the issue for me@adityadhawan22 suggestion worked for me! I already lost 4 hours on this and almost gave up. Thank you!
@fbeutel how did you re-generate the JWT secret? Experiencing the same issue
We had the same issue, but it seemed like re-generating the JWT secret (and therefore changing the API keys) solved the problem…
Also have this issue:
supabase/postgres │ 15.1.0.117 │ - supabase/gotrue │ v2.99.0 │ - postgrest/postgrest │ v11.2.0 │ - supabase/realtime │ v2.10.1 │ - supabase/storage-api │ v0.40.4 │ - supabase/edge-runtime │ v1.20.2 │ - supabase/studio │ 20230921-d657f29 │ - supabase/postgres-meta │ v0.68.0 │ - supabase/logflare │ 1.4.0 │ - bitnami/pgbouncer │ 1.20.1-debian-11-r39 │ - darthsim/imgproxy │ v3.8.0 │ -Error:
` WebSocket connection to 'ws://localhost:54321/realtime/v1/websocket?apikey={apiKey}&vsn=1.0.0: failed
` Code:
` const entriesChannel = supabase .channel(‘custom-all-channel’) .on(‘postgres_changes’, { event: ‘*’, schema: ‘public’, table: ‘entries’ }, (payload) => { console.log(‘Change received!’, payload); }) .subscribe();
`
dependencies:
"@supabase/auth-helpers-sveltekit": "^0.10.3", "@supabase/auth-ui-shared": "^0.1.8", "@supabase/auth-ui-svelte": "^0.2.7", "@supabase/supabase-js": "^2.38.1",Supabase CLI: 1.106.1