Check whether the socket still exists when keeping alive
authorRaphaël Jakse <raphael.trivabble@jakse.fr>
Sat, 16 May 2020 09:31:11 +0000 (11:31 +0200)
committerRaphaël Jakse <raphael.trivabble@jakse.fr>
Sat, 16 May 2020 09:31:11 +0000 (11:31 +0200)
server/trivabble-server.js

index bc31e9d6c50526285b51f5df24771735cab29a66..983e433a221711027514ea6c1ee7b98a8dd66195 100644 (file)
@@ -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);
 }