Forwarding events carried over after WebSocket reconnect doesn't work
Closed this issue · 1 comments
What is the problem?
When running the mock WebSocket server in strict mode (twitch event websocket start -S
), it is noticed that after the mock server restarts via reconnect testing the subscriptions carry over seemingly correctly, but cannot be forwarded like they did before the WebSocket reconnected.
This happens when forwarding to a specific session as well as forwarding to all clients. The relevant commands are:
> twitch event trigger channel.ban --transport=websocket
> twitch event trigger channel.ban --transport=websocket --session=<session_id>
Operating System
All
Architecture Version (x86, x64, arm, etc)
All
Steps to reproduce
- Start mock websocket server with -S
- Connect websocket client
- Subscribe to any event
- Confirm forwarding that event works
- Run reconnect testing
- Reconnect the WebSocket client to the URL provided by the reconnect message
- Verify event subscription exists
- Attempt to forward the same event and observe failure
Relevant log output
From forwarding CLI:
> # Subscribed to channel.ban via mock EventSub
> curl -X GET 'http://localhost:8080/eventsub/subscriptions' -H 'Client-Id: 4ofh8m0706jqpholgk00u3xvb4spct'
{"total":1,"total_cost":0,"max_total_cost":10,"pagination":{},"data":[{"id":"30ebc708-82b9-db08-3b74-6774cc8bee32","status":"enabled","type":"channel.ban","version":"1","created_at":"2024-03-12T18:18:56.7104022Z","cost":0,"condition":{"broadcaster_user_id":"57047445"},"transport":{"method":"websocket","session_id":"3eecdd64_c9e23329","connected_at":"2024-03-12T18:18:53.6964102Z"}}]}
> twitch event trigger channel.ban --transport=websocket
✔ Forwarded for use in mock EventSub WebSocket server
{"subscription":{"id":"ef467cce-4194-149c-dc0d-4137f41c267f","status":"enabled","type":"channel.ban","version":"1","condition":{"broadcaster_user_id":"65724368"},"transport":{"method":"websocket","session_id":"WebSocket-Server-Will-Set"},"created_at":"2024-03-12T18:19:54.2998115Z","cost":0},"event":{"banned_at":"2024-03-12T18:19:54.2998115Z","broadcaster_user_id":"65724368","broadcaster_user_login":"testBroadcaster","broadcaster_user_name":"testBroadcaster","ends_at":null,"is_permanent":true,"moderator_user_id":"73137767","moderator_user_login":"CLIModerator","moderator_user_name":"CLIModerator","reason":"This is a test event","user_id":"89311479","user_login":"testFromUser","user_name":"testFromUser"}}
> twitch event websocket reconnect
✔ Forwarded for use in mock EventSub WebSocket server
> # Reconnected WebSocket client to the URL the server provided
> curl -X GET 'http://localhost:8080/eventsub/subscriptions' -H 'Client-Id: 4ofh8m0706jqpholgk00u3xvb4spct'
{"total":1,"total_cost":0,"max_total_cost":10,"pagination":{},"data":[{"id":"30ebc708-82b9-db08-3b74-6774cc8bee32","status":"enabled","type":"channel.ban","version":"1","created_at":"2024-03-12T18:18:56.7104022Z","cost":0,"condition":{"broadcaster_user_id":"57047445"},"transport":{"method":"websocket","session_id":"06a89929_10f57612","connected_at":"2024-03-12T18:18:53.6964102Z"}}]}
> twitch event trigger channel.ban --transport=websocket
✗ EventSub WebSocket server failed to process event: [Error executing remote triggered EventSub: No clients with the subscribed to [channel.ban / 1]] Error executing remote triggered EventSub: No clients with the subscribed to [channel.ban / 1]
{"subscription":{"id":"825a89b8-05f8-8b65-70ce-444e76380867","status":"enabled","type":"channel.ban","version":"1","condition":{"broadcaster_user_id":"2754612"},"transport":{"method":"websocket","session_id":"WebSocket-Server-Will-Set"},"created_at":"2024-03-12T18:21:08.9709666Z","cost":0},"event":{"banned_at":"2024-03-12T18:21:08.9709666Z","broadcaster_user_id":"2754612","broadcaster_user_login":"testBroadcaster","broadcaster_user_name":"testBroadcaster","ends_at":null,"is_permanent":true,"moderator_user_id":"57421516","moderator_user_login":"CLIModerator","moderator_user_name":"CLIModerator","reason":"This is a test event","user_id":"28156716","user_login":"testFromUser","user_name":"testFromUser"}}
From server:
2024/03/12 11:18:35 Connect to the WebSocket server at: ws://127.0.0.1:8080/ws
2024/03/12 11:18:53 Client connected [c9e23329]
2024/03/12 11:18:53 [3eecdd64] Connections: (1) [ c9e23329 ]
2024/03/12 11:19:54 Sent [channel.ban / 1] to client [c9e23329]
2024/03/12 11:20:08 Initiating reconnect testing...
2024/03/12 11:20:08 Reconnect notices sent for server [3eecdd64]
2024/03/12 11:20:08 Will disconnect all existing clients in 30 seconds...
2024/03/12 11:20:19 read err [c9e23329]: websocket: close 1005 (no status)
2024/03/12 11:20:19 Disconnected client [c9e23329] with code [1000]
2024/03/12 11:20:19 [3eecdd64] Connections: (0) [ ]
2024/03/12 11:20:22 Client connected [10f57612]
2024/03/12 11:20:22 [06a89929] Connections: (1) [ 10f57612 ]
2024/03/12 11:20:38 All users disconnected from server [3eecdd64]
2024/03/12 11:20:38 Reconnect testing successful. Primary server is now [06a89929]
You may now execute reconnect testing again.
2024/03/12 11:21:08 Error executing remote triggered EventSub: No clients with the subscribed to [channel.ban / 1]
This is symptom of a larger issue: There should be 4 concepts in the mock WebSocket server:
- WebSocket Server
- WebSocket Server Manager
- EventSub Manager
- Gateway (to handle HTTP entry)
However, when I set this up I managed to put the EventSub Manager inside of the WebSocket server, which is incorrect because EventSub subscriptions are technically transport agnostic.
This should all be fixed in the future, but its more than the quick fix I want to put into place to fix this. For work on this tech debt, see #317.