From f2892aba0beeae7c9be930221655d7da6094c5f1 Mon Sep 17 00:00:00 2001 From: Max Stepanov Date: Thu, 22 Jun 2023 03:33:11 -0400 Subject: [PATCH] fix: use same scope for setTimeout and clearTimeout calls (#1568) Details: - engine.io-client sets clearTimeoutFn and setTimeoutFn function depending on settings passed to manager - socker.io-client is using manager.setTimeoutFn to start connection monitoring timer, but is using regular clearTimeout function to stop it when connection is established - in some setups it is causing timer fail to stop and it will break connection every _timeout_ milliseconds (which is 20000 by default) --- lib/manager.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/manager.ts b/lib/manager.ts index 8371824b..b3146039 100644 --- a/lib/manager.ts +++ b/lib/manager.ts @@ -129,6 +129,7 @@ export class Manager< // @ts-ignore private backoff: Backoff; private setTimeoutFn: typeof setTimeout; + private clearTimeoutFn: typeof clearTimeout; private _reconnection: boolean; private _reconnectionAttempts: number; private _reconnectionDelay: number; @@ -360,8 +361,8 @@ export class Manager< timer.unref(); } - this.subs.push(function subDestroy(): void { - clearTimeout(timer); + this.subs.push(() => { + this.clearTimeoutFn(timer); }); } @@ -605,8 +606,8 @@ export class Manager< timer.unref(); } - this.subs.push(function subDestroy() { - clearTimeout(timer); + this.subs.push(() => { + this.clearTimeoutFn(timer); }); } }