Skip to content

Commit

Permalink
Fix for Ylianst#2777
Browse files Browse the repository at this point in the history
  • Loading branch information
Ylianst committed Jun 15, 2021
1 parent db60c35 commit ce21e9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 16 additions & 1 deletion meshdesktopmultiplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ function CreateMeshRelayEx2(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(obj.close, cookie.expire - currentTime); }
setExpireTimer();

// Mark this relay session as authenticated if this is the user end.
obj.authenticated = (user != null);
Expand Down Expand Up @@ -1205,6 +1205,21 @@ function CreateMeshRelayEx2(parent, ws, req, domain, user, cookie) {
}
}

// Set the session expire timer
function setExpireTimer() {
if (obj.expireTimer != null) { clearTimeout(obj.expireTimer); delete obj.expireTimer; }
if (cookie && (typeof cookie.expire == 'number')) {
const timeToExpire = (cookie.expire - Date.now());
if (timeToExpire < 1) {
obj.close();
} else if (timeToExpire >= 0x7FFFFFFF) {
obj.expireTimer = setTimeout(setExpireTimer, 0x7FFFFFFF); // Since expire timer can't be larger than 0x7FFFFFFF, reset timer after that time.
} else {
obj.expireTimer = setTimeout(obj.close, timeToExpire);
}
}
}

// If this is not an authenticated session, or the session does not have routing instructions, just go ahead an connect to existing session.
performRelay(0);
return obj;
Expand Down
8 changes: 5 additions & 3 deletions meshrelay.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,11 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
function setExpireTimer() {
if (obj.expireTimer != null) { clearTimeout(obj.expireTimer); delete obj.expireTimer; }
if (cookie && (typeof cookie.expire == 'number')) {
const timeToExpire = (cookie.expire - currentTime);
if (timeToExpire >= 0x7FFFFFFF) {
obj.expireTimer = setTimeout(setExpireTimer, 0x7FFFFFFF);
const timeToExpire = (cookie.expire - Date.now());
if (timeToExpire < 1) {
closeBothSides();
} else if (timeToExpire >= 0x7FFFFFFF) {
obj.expireTimer = setTimeout(setExpireTimer, 0x7FFFFFFF); // Since expire timer can't be larger than 0x7FFFFFFF, reset timer after that time.
} else {
obj.expireTimer = setTimeout(closeBothSides, timeToExpire);
}
Expand Down

0 comments on commit ce21e9a

Please sign in to comment.