supabase / realtime-js

An isomorphic Javascript client for Supabase Realtime server.
https://supabase.com
MIT License
315 stars 54 forks source link

Realtime - Unable to communicate with host when running client within WSL #255

Open Zendrex opened 1 year ago

Zendrex commented 1 year ago

Bug report

Describe the bug

It seems that the supabase client is unable to communicate with the realtime wss api beyond initial connection. Furthermore, there is no provided error as to why the issue is occurring via status CHANNEL_ERROR. NOTE: This is for a backend application, not front-end.

I was able to successfully connect to the realtime api and receive updates by doing the following below outside of the package by utilizing wscat. This shows that my WSL configuration is valid and able to communicate normally with the API.

Initial command. wscat --connect "wss://<project_id>.supabase.co/realtime/v1/websocket?apikey=<apikey>&vsn=1.0.0"

Sent message(s)

{
  "topic": "realtime:custom-all-channel",
  "event": "phx_join",
  "payload": {
    "config": {
      "broadcast": {
        "ack": false,
        "self": false
      },
      "presence": {
        "key": ""
      },
      "postgres_changes": [
        {
          "event": "*",
          "schema": "public",
          "table": "<table_here>"
        }
      ]
    },
    "access_token": "<api_key>"
  },
  "ref": "1",
  "join_ref": "1"
}

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

Create a basic nodejs & supabase application within WSL Try connecting to the realtime api

Expected behavior

Connection and successful subscription to realtime events.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

Additional context

Code being used to test.

import { REALTIME_SUBSCRIBE_STATES, createClient } from '@supabase/supabase-js'

const SUPABASE_REALTIME_URL = 'https://<project_id>.supabase.co'
const SUPABASE_KEY = 'public-anon-key'
const supabase = createClient(SUPABASE_REALTIME_URL, SUPABASE_KEY, {
    realtime: {
        params: {
            eventsPerSecond: 1000,
        },
    },
})

const channel = supabase.channel('custom-all-channel')
    .on(
        'postgres_changes',
        { event: '*', schema: 'public', table: '<table_name>' },
        (payload) => {
            console.log('Change received!', payload)
        },
    )

channel.subscribe((status: `${REALTIME_SUBSCRIBE_STATES}`, err) => {
    if (status === REALTIME_SUBSCRIBE_STATES.SUBSCRIBED)
        console.log('Subscribed to channel!')

    if (status === REALTIME_SUBSCRIBE_STATES.CHANNEL_ERROR)
        // # err returns undefined?!?!
        console.log('Error subscribing to channel!', err)
})
kevinco26 commented 10 months ago

Facing the same issue for one of my projects but not for the other.

Also same with err being undefined https://github.com/orgs/supabase/discussions/19263

I also opened a ticket as well

filipecabaco commented 10 months ago

@Zendrex could you please open a ticket? That way I might be able to unblock your project.

We might have an issue when we're creating some of the data on our side to connect to the project database. Already checking with the relevant teams 👀

groud commented 6 months ago

Hi. It's probably not fully related to the original issue, but I had this same err = undefined issue on a self-hosted instance. Basically, it happens when supabase is unreachable (mainly because I did not port-forward, on purpose).

I kind of was expecting some sort of an error message instead, so there might be something to investigate there. This is happening with the latest release for us, and I could not find where the problem would be, as the callback seems called correctly in the source code.

filipecabaco commented 6 months ago

We actually found a bug related with this where an Invalid JWT is not being reported properly in our JS client and we're still working in checking if this is something at the server side or client side.

The connection issue @groud mentioned might also be related with this issue of lack of proper error reporting on subscribe as such I will keep this issue open as we work on it