twitchdev / twitch-cli

The official Twitch CLI to make developing on Twitch easier.
Apache License 2.0
604 stars 71 forks source link

[Bug] Websocket reconnect old socket doesn't emit #324

Closed BarryCarlyon closed 4 months ago

BarryCarlyon commented 4 months ago

What is the problem?

I belive that the CLI differs from production in behaviour

I believe production sends a reconnect message but still sends events on the old socket till grace period/user disconnect so a developer has to be aware of duplicate messaging during the reconnect window if they didn't disconnect the old socket yet.

The CLI only sends events to the most recent socket born leaving the old/dying server eventless.

So we can't test reconnect logic properly as the CLI behaviour differs

Operating System

N/A

Architecture Version (x86, x64, arm, etc)

N/A

Steps to reproduce

  1. Window (a) make server twitch event websocket start-server
  2. Window (b) Connect a client
  3. Window (c) use a spam server script:
#!/bin/bash

while true
do
    twitch event trigger channel.ban --transport=websocket
    sleep 2
done
  1. Window (d) issue a reconnect twitch event websocket reconnect

Relevant log output

2024/05/23 08:02:41 Connect to the WebSocket server at: ws://127.0.0.1:8080/ws
2024/05/23 08:02:41 Warning for remote triggered EventSub: No clients in server [4dd51198]
2024/05/23 08:02:43 Warning for remote triggered EventSub: No clients in server [4dd51198]
2024/05/23 08:02:44 Client connected [88679f95]
2024/05/23 08:02:44 [4dd51198] Connections: (1) [ 88679f95 ]
2024/05/23 08:02:46 Sent [channel.ban / 1] to client [88679f95]
2024/05/23 08:02:48 Sent [channel.ban / 1] to client [88679f95]
2024/05/23 08:02:49 Initiating reconnect testing...
2024/05/23 08:02:49 Reconnect notices sent for server [4dd51198]
2024/05/23 08:02:49 Will disconnect all existing clients in 30 seconds...
2024/05/23 08:02:50 Warning for remote triggered EventSub: No clients in server [db5311e0]
2024/05/23 08:02:52 Warning for remote triggered EventSub: No clients in server [db5311e0]
2024/05/23 08:02:54 Warning for remote triggered EventSub: No clients in server [db5311e0]
2024/05/23 08:02:56 Warning for remote triggered EventSub: No clients in server [db5311e0]
2024/05/23 08:02:58 Warning for remote triggered EventSub: No clients in server [db5311e0]
2024/05/23 08:02:59 read err [88679f95]: websocket: close 1005 (no status)
2024/05/23 08:02:59 Disconnected client [88679f95] with code [1000]
2024/05/23 08:02:59 [4dd51198] Connections: (0) [  ]

Logically the old socket should still be getting events till grace period expires.

Xemdo commented 4 months ago

I have gotten confirmation from the EventSub team that you should not be getting messages on the old connection in production. Is this something you have experienced? If so, it may be worth noting to https://github.com/twitchdev/issues

BarryCarlyon commented 4 months ago

Then I misunderstood. I thought messages were sent to both during the change over period.