Clear connection timeout on disconnect (#4681)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user