Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
fix: avoids restarting transport if explicitly closed
Browse files Browse the repository at this point in the history
  • Loading branch information
ganchoradkov committed Feb 3, 2023
1 parent 1d0c1d4 commit 8934fba
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/core/src/controllers/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Relayer extends IRelayer {
public transportExplicitlyClosed = false;

private initialized = false;

private reconnecting = false;
private relayUrl: string;
private projectId: string | undefined;
constructor(opts: RelayerOptions) {
Expand Down Expand Up @@ -155,8 +155,10 @@ export class Relayer extends IRelayer {
}

public async transportOpen(relayUrl?: string) {
if (this.reconnecting) return;
this.relayUrl = relayUrl || this.relayUrl;
this.transportExplicitlyClosed = false;
this.reconnecting = true;
try {
await Promise.all([
new Promise<void>((resolve) => {
Expand All @@ -181,14 +183,20 @@ export class Relayer extends IRelayer {
} catch (e: unknown | Error) {
const error = e as Error;
if (!/socket hang up/i.test(error.message)) {
throw new Error(error.message);
throw e;
}
this.logger.error(error);
this.logger.error(e);
this.events.emit(RELAYER_EVENTS.transport_closed);
} finally {
this.reconnecting = false;
}
}

public async restartTransport(relayUrl?: string) {
if (this.transportExplicitlyClosed) {
return;
}

await this.transportClose();
await new Promise<void>((resolve) => setTimeout(resolve, RELAYER_RECONNECT_TIMEOUT));
await this.transportOpen(relayUrl);
Expand Down

0 comments on commit 8934fba

Please sign in to comment.