Skip to content

Commit

Permalink
Stop retrying if we're trying to close the connection to avoid hangin…
Browse files Browse the repository at this point in the history
…g scripts
  • Loading branch information
pxpeterxu committed Jun 28, 2024
1 parent 38b7062 commit 899d092
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class Manager extends EventEmitter {
private readonly retryStrategy: RetryStrategy;
private nextRetryTimeoutForExponentialBackoff = DEFAULT_RETRY_TIMEOUT_MS_FOR_EXPONENTIAL_BACKOFF;
private retryTimeout?: ReturnType<typeof setTimeout> = undefined;
private isClosing = false;

private connectionCallbacks: Map<ConnectionEvents, (e:Error) => void> = new Map<ConnectionEvents, () => void>

Expand Down Expand Up @@ -95,7 +96,7 @@ export class Manager extends EventEmitter {
}

private shouldTryToReconnect(error: Error) {
if (this.isRetryableError(error)) {
if (this.isRetryableError(error) && !this.isClosing) {
const { maxConnectRetries } = this.retryStrategy;
return maxConnectRetries < 0 || this.retries < maxConnectRetries;
} else {
Expand Down Expand Up @@ -161,6 +162,11 @@ export class Manager extends EventEmitter {
}

close() {
this.isClosing = true;
if (this.retryTimeout) {
clearTimeout(this.retryTimeout);
}

this.emit('closing');
this.flush();
this.removeEventListeners();
Expand Down

0 comments on commit 899d092

Please sign in to comment.