From a1cb07670dc488bf913936ba533675989854b4c1 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 25 May 2021 12:35:41 -0700 Subject: [PATCH] Fix for #2687. Relay would not work for very long expire times. --- meshrelay.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/meshrelay.js b/meshrelay.js index a27b4318..7dc79f05 100644 --- a/meshrelay.js +++ b/meshrelay.js @@ -144,7 +144,7 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) { delete obj.id; delete obj.ws; delete obj.peer; - delete obj.expireTimer; + if (obj.expireTimer != null) { clearTimeout(obj.expireTimer); delete obj.expireTimer; } // Unsubscribe if (obj.pid != null) { parent.parent.RemoveAllEventDispatch(obj); } @@ -295,6 +295,13 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) { } } + // Check that both sides have websocket connections + if ((obj.ws == null) || (relayinfo.peer1.ws == null)) { + relayinfo.peer1.close(); + obj.close(); + return null; + } + // Connect to peer obj.peer = relayinfo.peer1; obj.peer.peer = obj; @@ -767,7 +774,10 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) { } // If this session has a expire time, setup the expire timer now. - if (cookie && (typeof cookie.expire == 'number')) { obj.expireTimer = setTimeout(closeBothSides, cookie.expire - currentTime); } + if (cookie && (typeof cookie.expire == 'number')) { + const timeToExpire = (cookie.expire - currentTime); + if (timeToExpire < 0x7FFFFFFF) { obj.expireTimer = setTimeout(closeBothSides, timeToExpire); } // Only set the timeout if it fits in 32bit signed integer. + } // Mark this relay session as authenticated if this is the user end. obj.authenticated = (user != null); @@ -1097,7 +1107,7 @@ function CreateLocalRelayEx(parent, ws, req, domain, user, cookie) { delete obj.nodeid; delete obj.meshid; delete obj.tcpport; - delete obj.expireTimer; + if (obj.expireTimer != null) { clearTimeout(obj.expireTimer); delete obj.expireTimer; } if (obj.client != null) { obj.client.destroy(); delete obj.client; } // Close the client socket if (obj.pingtimer != null) { clearInterval(obj.pingtimer); delete obj.pingtimer; } if (obj.pongtimer != null) { clearInterval(obj.pongtimer); delete obj.pongtimer; }