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

Rewrite session_reconnect handling to follow twitch rules #310

Merged
merged 4 commits into from
May 30, 2024

Conversation

Latent-Logic
Copy link
Contributor

https://dev.twitch.tv/docs/eventsub/handling-websocket-events/#reconnect-message
When a session_reconnect message is received, the client should create a new connection to the reconnect url while leaving the existing connection open to receive messages until the new connection gets the welcome message. This way no events should be missed during the handoff.

In my testing this fixes #286 where the connection gets broken because of a Websocket closing: 4007 - Invalid reconnect

I'll update this PR with logs from a repro of the issue once twitch sends me another session_reconnect. (It worked for a slightly less cleaned up version of these changes previously, but it had a bunch of debug logging and hooked in slightly different ways)

https://dev.twitch.tv/docs/eventsub/handling-websocket-events/#reconnect-message
When a session_reconnect message is received, the client should create
a new connection to the reconnect url while leaving the existing
connection open to receive messages until the new connection gets
the welcome message. This way no events should be missed during the
handoff.

In my testing this fixes Teekeks#286 where the connection gets broken
@Latent-Logic
Copy link
Contributor Author

Repro of the 4007 issue:

2024-05-30 10:28:46,681 DEBUG   twitchAPI.eventsub.websocket    got session keep alive
2024-05-30 10:28:56,680 DEBUG   twitchAPI.eventsub.websocket    got session keep alive
2024-05-30 10:29:05,753 DEBUG   twitchAPI.eventsub.websocket    got request from websocket to reconnect
2024-05-30 10:29:05,753 DEBUG   twitchAPI.eventsub.websocket    reconnecting using wss://cell-a.eventsub.wss.twitch.tv/ws?challenge=a4749afd-7957-4ad9-bd38-b5027ff50018&id=AgoQ9OavRrveQSiC1PBorLcHDxIGY2VsbC1h...
2024-05-30 10:29:05,792 DEBUG   twitchAPI.eventsub.websocket    websocket is closing
2024-05-30 10:29:05,905 INFO    twitchAPI.eventsub.websocket    Websocket closing: 4007 - Invalid reconnect

2024-05-30 11:21:31,857 DEBUG   twitchAPI.eventsub.websocket    stopping websocket EventSub...

With this MR:

2024-05-30 10:23:38,105	DEBUG	twitchAPI.eventsub.websocket	got session keep alive
2024-05-30 10:23:48,056	DEBUG	twitchAPI.eventsub.websocket	got session keep alive
2024-05-30 10:23:58,057	DEBUG	twitchAPI.eventsub.websocket	got session keep alive
2024-05-30 10:24:03,635	DEBUG	twitchAPI.eventsub.websocket	got request from websocket to reconnect, reconnect url: wss://cell-a.eventsub.wss.twitch.tv/ws?challenge=613f1eb7-396e-4b67-98d5-7360d9197b5b&id=AgoQPnH5Rj6KQC2h53YJGlnHKRIGY2VsbC1h
2024-05-30 10:24:04,102	DEBUG	twitchAPI.eventsub.websocket	websocket session_reconnect completed
2024-05-30 10:24:14,151	DEBUG	twitchAPI.eventsub.websocket	got session keep alive
2024-05-30 10:24:24,096	DEBUG	twitchAPI.eventsub.websocket	got session keep alive
2024-05-30 10:24:34,098	DEBUG	twitchAPI.eventsub.websocket	got session keep alive
2024-05-30 10:24:44,101	DEBUG	twitchAPI.eventsub.websocket	got session keep alive

@Teekeks Teekeks merged commit b608a57 into Teekeks:master May 30, 2024
@Latent-Logic Latent-Logic deleted the handle-session-reconnect branch May 30, 2024 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EventSub Websocket failing to reconnect
2 participants