Skip to content

Commit f2892ab

Browse files
authored
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)
1 parent 5bc94b5 commit f2892ab

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Diff for: lib/manager.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export class Manager<
129129
// @ts-ignore
130130
private backoff: Backoff;
131131
private setTimeoutFn: typeof setTimeout;
132+
private clearTimeoutFn: typeof clearTimeout;
132133
private _reconnection: boolean;
133134
private _reconnectionAttempts: number;
134135
private _reconnectionDelay: number;
@@ -360,8 +361,8 @@ export class Manager<
360361
timer.unref();
361362
}
362363

363-
this.subs.push(function subDestroy(): void {
364-
clearTimeout(timer);
364+
this.subs.push(() => {
365+
this.clearTimeoutFn(timer);
365366
});
366367
}
367368

@@ -605,8 +606,8 @@ export class Manager<
605606
timer.unref();
606607
}
607608

608-
this.subs.push(function subDestroy() {
609-
clearTimeout(timer);
609+
this.subs.push(() => {
610+
this.clearTimeoutFn(timer);
610611
});
611612
}
612613
}

0 commit comments

Comments
 (0)