Clear connection timeout on disconnect (#4681)

This commit is contained in:
Jaco
2022-03-23 16:09:25 +02:00
committed by GitHub
parent 044aecbfc3
commit 63ba84a641
+10 -3
View File
@@ -107,6 +107,8 @@ export class WsProvider implements ProviderInterface {
#subscriptions: Record<string, WsStateSubscription> = {};
#timeoutId?: NodeJS.Timeout | null = null;
#websocket: WebSocket | null;
/**
@@ -147,9 +149,6 @@ export class WsProvider implements ProviderInterface {
resolve(this);
});
});
// timeout any handlers that have not had a response
setInterval(() => this.#timeout(), TIMEOUT_INTERVAL);
}
/**
@@ -209,6 +208,9 @@ export class WsProvider implements ProviderInterface {
this.#websocket.onerror = this.#onSocketError;
this.#websocket.onmessage = this.#onSocketMessage;
this.#websocket.onopen = this.#onSocketOpen;
// timeout any handlers that have not had a response
this.#timeoutId = setInterval(() => this.#timeout(), TIMEOUT_INTERVAL);
} catch (error) {
l.error(error);
@@ -414,6 +416,11 @@ export class WsProvider implements ProviderInterface {
this.#websocket = null;
}
if (this.#timeoutId) {
clearInterval(this.#timeoutId);
this.#timeoutId = null;
}
this.#emit('disconnected');
// reject all hanging requests