From: Raphaƫl Jakse Date: Sat, 16 May 2020 09:31:11 +0000 (+0200) Subject: Check whether the socket still exists when keeping alive X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=c6060a685eca59afff171042105d97c8c6687efa;p=trivabble.git Check whether the socket still exists when keeping alive --- 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); }