From 5da5930af18d447d82dd4c4f7c2810257479fec2 Mon Sep 17 00:00:00 2001 From: Allan Merland Date: Tue, 26 Nov 2024 09:47:36 +0100 Subject: [PATCH 1/2] 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); From 52f7d18e7e79762c97ad2d4638c860501c4f4b0e Mon Sep 17 00:00:00 2001 From: Allan Merland Date: Mon, 2 Dec 2024 11:37:06 +0100 Subject: [PATCH 2/2] refactor(protocols): remove useless check --- lib/core/network/protocols/httpwsProtocol.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/core/network/protocols/httpwsProtocol.js b/lib/core/network/protocols/httpwsProtocol.js index af0d12e1cb..b9876134b2 100644 --- a/lib/core/network/protocols/httpwsProtocol.js +++ b/lib/core/network/protocols/httpwsProtocol.js @@ -317,11 +317,7 @@ class HttpWsProtocol extends Protocol { // 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") - ) { + if (code === 1006 && reason.startsWith("Received too big message")) { global.kuzzle.log.error( `[${connection.id}] connection closed: payload exceeded the threshold`, );