From 7cb544c7a5c1fe572b82c5f9366621eef61034c4 Mon Sep 17 00:00:00 2001 From: Nisarg Jhaveri Date: Thu, 9 Jan 2025 00:39:05 +0530 Subject: [PATCH] Add timeout for fetching server status --- src/client/ServerConnection.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/ServerConnection.ts b/src/client/ServerConnection.ts index 5c20235..89bcb6a 100644 --- a/src/client/ServerConnection.ts +++ b/src/client/ServerConnection.ts @@ -97,9 +97,9 @@ export class ServerConnection { } } - getServerStatus = async (): Promise => { + getServerStatus = async (timeout: number = 10000): Promise => { await this.lastServerStatusPromise - this.lastServerStatusPromise = this.fetchServerStatus(); + this.lastServerStatusPromise = this.fetchServerStatus(timeout); const status = await this.lastServerStatusPromise; @@ -114,12 +114,13 @@ export class ServerConnection { setTimeout(this.updateStatusLoop, 5000); } - private fetchServerStatus = async (): Promise => { + private fetchServerStatus = async (timeout: number): Promise => { try { const res = await this.fetch(url.status, { headers: { 'Content-Type': 'application/json' }, + signal: AbortSignal.timeout(timeout) }); if (res.status !== 200) {