mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 15:30:41 +09:00
Handle WebSocket errors before the handshake completes
WsServer attached no error listener to a new socket. WsServerConnector adds one, but only after the handshake. ws emits an error for an invalid frame, for example a close frame with the reserved status code 1006, and an error event with no listener throws. That stopped the controller. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F7obMEi4L4PzUQ8w8q9Uyz
This commit is contained in:
1 parent
ae6e25d1b9
commit
16666c3ee0
2 files changed
+26
No files matched your search
@@ -116,6 +116,13 @@ export default class WsServer {
|
||||
handleConnection(socket: lib.WebSocketClusterio, req: IncomingMessage) {
|
||||
logger.verbose(`WsServer | new connection from ${this.remoteAddr(req)}`);
|
||||
|
||||
// ws emits errors like invalid frames on the socket, and an error with
|
||||
// no listener crashes the controller. The connector adds its own
|
||||
// listener, but only once the handshake has completed.
|
||||
socket.on("error", (err: Error) => {
|
||||
logger.verbose(`WsServer | error on connection from ${this.remoteAddr(req)}: ${err.message}`);
|
||||
});
|
||||
|
||||
// Track statistics
|
||||
wsConnectionsCounter.inc();
|
||||
socket.on("message", (message: WebSocket.RawData) => {
|
||||
|
||||
Reference in new issue
Block a user