Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eech heartbeat and channel join sends a new accessToken, even if token hasn't changed, same for channel join #434

Open
2 tasks done
lauri865 opened this issue Nov 11, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@lauri865
Copy link
Contributor

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Each setAuth call sends a new access_token payload (all good):

setAuth(token: string | null): void {
this.accessToken = token
this.channels.forEach((channel) => {
token && channel.updateJoinPayload({ access_token: token })
if (channel.joinedOnce && channel._isJoined()) {
channel._push(CHANNEL_EVENTS.access_token, { access_token: token })
}
})
}

Each sendHeartBeat call calls setAuth (even if accessToken hasn't changeD), which results in a lot of unnecessary messages being sent:

private _sendHeartbeat() {
if (!this.isConnected()) {
return
}
if (this.pendingHeartbeatRef) {
this.pendingHeartbeatRef = null
this.log(
'transport',
'heartbeat timeout. Attempting to re-establish connection'
)
this.conn?.close(WS_CLOSE_NORMAL, 'hearbeat timeout')
return
}
this.pendingHeartbeatRef = this._makeRef()
this.push({
topic: 'phoenix',
event: 'heartbeat',
payload: {},
ref: this.pendingHeartbeatRef,
})
this.setAuth(this.accessToken)
}

Also, each call to join a channel triggers new call to access_token, even though the accessToken is also sent with the phx_join event already.

Are we being charged for all these unnecessary messages being sent?

@lauri865 lauri865 added the bug Something isn't working label Nov 11, 2024
@lauri865
Copy link
Contributor Author

lauri865 commented Nov 11, 2024

We removed those additional payloads, and everything seems to be working fine at initial look:

  • No access token sent with every heartbeat (gets rid of 2 extra messages per minute per each connection, much larger payloads than the heartbeats themselves)
  • If access token hasn't changed – skip the message.event === "access_token" (gets rid of 1 extra message per each page view)

We did it on a custom transport level for now.

@filipecabaco
Copy link
Member

this is the expected behaviour, this are not accounted for for you total messages and if they don't change our server just ignores the message so this is low impact on client and server.

could you provide more information why could be a bigger concern?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants