Skip to content

Commit

Permalink
fix: use same scope for setTimeout and clearTimeout calls (#1568)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
mast committed Jun 22, 2023
1 parent 5bc94b5 commit f2892ab
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/manager.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -360,8 +361,8 @@ export class Manager<
timer.unref();
}

this.subs.push(function subDestroy(): void {
clearTimeout(timer);
this.subs.push(() => {
this.clearTimeoutFn(timer);
});
}

Expand Down Expand Up @@ -605,8 +606,8 @@ export class Manager<
timer.unref();
}

this.subs.push(function subDestroy() {
clearTimeout(timer);
this.subs.push(() => {
this.clearTimeoutFn(timer);
});
}
}
Expand Down

0 comments on commit f2892ab

Please sign in to comment.