From c6060a685eca59afff171042105d97c8c6687efa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Jakse?= Date: Sat, 16 May 2020 11:31:11 +0200 Subject: [PATCH] Check whether the socket still exists when keeping alive --- server/trivabble-server.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server/trivabble-server.js b/server/trivabble-server.js index bc31e9d..983e433 100644 --- a/server/trivabble-server.js +++ b/server/trivabble-server.js @@ -191,15 +191,17 @@ function stopKeepAlive(responseAndType) { function keepAlive(responseAndType) { stopKeepAlive(responseAndType); responseAndType.keepAliveTimeout = setTimeout(function keepAliveTimeout() { - responseAndType[0].write( - responseAndType[1] === REQUEST_TYPE_WEBSOCKET - ? webSocketPingBuffer - : ( - responseAndType[1] === REQUEST_TYPE_SSE - ? ":\n\n" - : "2[]" - ) - ); + if (responseAndType[0]) { + responseAndType[0].write( + responseAndType[1] === REQUEST_TYPE_WEBSOCKET + ? webSocketPingBuffer + : ( + responseAndType[1] === REQUEST_TYPE_SSE + ? ":\n\n" + : "2[]" + ) + ); + } }, KEEP_ALIVE); } -- 2.30.2