Improved fix for #2687
Ylian Saint-Hilaire committed
May 25, 2021 at 15:36 UTC
574bff25182e32e73d6e41016e29908d0c98c50f
1 file changed
+14
-4
meshrelay.js
+14
-4
@@ -615,6 +615,19 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
615
closeBothSides();
616
});
617
618
+ // Set the session expire timer
619
+ function setExpireTimer() {
620
+ if (obj.expireTimer != null) { clearTimeout(obj.expireTimer); delete obj.expireTimer; }
621
+ if (cookie && (typeof cookie.expire == 'number')) {
622
+ const timeToExpire = (cookie.expire - currentTime);
623
+ if (timeToExpire >= 0x7FFFFFFF) {
624
+ obj.expireTimer = setTimeout(setExpireTimer, 0x7FFFFFFF);
625
+ } else {
626
+ obj.expireTimer = setTimeout(closeBothSides, timeToExpire);
627
+ }
628
+ }
629
+ }
630
+
631
// Close both our side and the peer side.
632
function closeBothSides() {
633
if (obj.id != null) {
@@ -770,10 +783,7 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
783
}
784
785
// If this session has a expire time, setup the expire timer now.
773
- if (cookie && (typeof cookie.expire == 'number')) {
774
- const timeToExpire = (cookie.expire - currentTime);
775
- if (timeToExpire < 0x7FFFFFFF) { obj.expireTimer = setTimeout(closeBothSides, timeToExpire); } // Only set the timeout if it fits in 32bit signed integer.
776
- }
786
+ setExpireTimer();
787
788
// Mark this relay session as authenticated if this is the user end.
789
obj.authenticated = (user != null);