From 5da5930af18d447d82dd4c4f7c2810257479fec2 Mon Sep 17 00:00:00 2001 From: Allan Merland Date: Tue, 26 Nov 2024 09:47:36 +0100 Subject: [PATCH] feat(protocols): add logging socket closing --- lib/core/network/protocols/httpwsProtocol.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/core/network/protocols/httpwsProtocol.js b/lib/core/network/protocols/httpwsProtocol.js index 318f4b2c51..af0d12e1cb 100644 --- a/lib/core/network/protocols/httpwsProtocol.js +++ b/lib/core/network/protocols/httpwsProtocol.js @@ -313,12 +313,26 @@ class HttpWsProtocol extends Protocol { return; } + const reason = Buffer.from(message || "").toString(); + + // This hack is only here to indicate that uWebSockets killed the connection early + // because the received payload exceeded the configured threshold. + if ( + code === 1006 && + typeof reason === "string" && + reason.startsWith("Received too big message") + ) { + global.kuzzle.log.error( + `[${connection.id}] connection closed: payload exceeded the threshold`, + ); + } + if (debugWS.enabled) { debugWS( "[%s] received a `close` event (CODE: %d, REASON: %s)", connection.id, code, - Buffer.from(message || "").toString(), + reason, ); } this.entryPoint.removeConnection(connection.id);