Skip to content

fix: Refine WebSocket connection management logic#145

Open
bretamerman wants to merge 1 commit intostoatchat:mainfrom
bretamerman:websockets-connection-timeouts
Open

fix: Refine WebSocket connection management logic#145
bretamerman wants to merge 1 commit intostoatchat:mainfrom
bretamerman:websockets-connection-timeouts

Conversation

@bretamerman
Copy link

adds guards to the heartbeat interval to prevent a send with an invalid socket updates connection timeout to use the connection timeout option uses clearTimeout for setTimeout and clearInterval for setInterval

@bretamerman
Copy link
Author

Had a bot that was running the other day randomly die on me. Stack trace shows it failed on this line, this.send({ type: "Ping", data: +new Date() });.

2026-03-18 11:35:28.317 [error]: Client error occurred: Received network error or non-101 status code.
2026-03-18 11:35:29.775 [error]: Uncaught Exception: Sent before connected. {
  "stack": "InvalidStateError: Sent before connected.\n    at new DOMException (node:internal/per_context/domexception:53:5)\n    at WebSocket.send (node:internal/deps/undici/undici:12680:17)\n    at EventClient.send (file:///Users/.../node_modules/revolt.js/lib/events/EventClient.js:123:22)\n    at Timeout._onTimeout (file:///Users/.../node_modules/revolt.js/lib/events/EventClient.js:75:22)\n    at listOnTimeout (node:internal/timers:614:17)\n    at processTimers (node:internal/timers:549:7)"
}

adds guards to the heartbeat interval to prevent a send with an invalid socket
updates connection timeout to use the connection timeout option
uses clearTimeout for setTimeout and clearInterval for setInterval

Signed-off-by: Bret Amerman <bret.amerman@icloud.com>
@bretamerman bretamerman force-pushed the websockets-connection-timeouts branch from 08d28d9 to 2d5f1a4 Compare March 20, 2026 01:54
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.

1 participant