Unknown Error on Channel for realtime subscriptions after updating to latest libraries

I updated everything yesterday and have started getting errors from the realtime subscriptions in my test env:
Subscription error: Error: "Unknown Error on Channel"
Subscription error: Error: "Unknown Error on Channel"
This was the websocket conversation:
{
"topic": "realtime:subscription_manager:1",
"event": "phx_join",
"payload": {
"config": {
"broadcast": {
"ack": false,
"self": false
},
"presence": {
"key": "",
"enabled": false
},
"postgres_changes": [
{
"event": "*",
"schema": "public",
"table": "club_permissions"
}
],
"private": false
}
},
"ref": "1",
"join_ref": "1"
}
{
"topic": "realtime:subscription_manager:1",
"event": "phx_join",
"payload": {
"config": {
"broadcast": {
"ack": false,
"self": false
},
"presence": {
"key": "",
"enabled": false
},
"postgres_changes": [
{
"event": "*",
"schema": "public",
"table": "club_permissions"
}
],
"private": false
}
},
"ref": "1",
"join_ref": "1"
}
{
"ref": "1",
"event": "phx_reply",
"payload": {
"status": "error",
"response": {
"reason": "Unknown Error on Channel"
}
},
"topic": "realtime:subscription_manager:1"
}
{
"ref": "1",
"event": "phx_reply",
"payload": {
"status": "error",
"response": {
"reason": "Unknown Error on Channel"
}
},
"topic": "realtime:subscription_manager:1"
}
The log of the realtime docker container:
03:13:36.470 project=realtime-dev external_id=realtime-dev error_code=UnknownErrorOnChannel [error] UnknownErrorOnChannel: :invalid_token
03:13:36.470 project=realtime-dev external_id=realtime-dev error_code=UnknownErrorOnChannel [error] UnknownErrorOnChannel: :invalid_token
So it is saying the token is invalid... but that's not a normal auth token as per https://supabase.com/docs/guides/realtime/error_codes, and obviously I'm using the token to fetch all the data on the screen so it should be valid. I've tried removing and rebuilding the whole local docker setup. Anything I can do further with this to debug it?
1 Reply
jemmyw
jemmywOP3d ago
so it turns out it is a token problem but its still confusing. The first message to realtime (as posted above) doesn't include the access token. If I change my code to retry the subsription then the second try succeeds. It's like realtime is not getting the access token the first time it tries, even though the client is logged in. In fact, I know it has the access token because I can call:
console.log(await supabase.realtime.accessToken?.());
console.log(await supabase.realtime.accessToken?.());
and it outputs the token, but the subsequent first subscription still fails If I put this:
supabase.auth.getSession().then((response) => {
supabase.realtime.setAuth(response.data.session?.access_token);
});
supabase.auth.getSession().then((response) => {
supabase.realtime.setAuth(response.data.session?.access_token);
});
In my onAuthStateChange handler then things work as they did before I updated. This seems like a bug or I'm initializing things incorrectly somewhere

Did you find this page helpful?