Skip to content

Commit 7cb544c

Browse files
committed
Add timeout for fetching server status
1 parent e15cd68 commit 7cb544c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/client/ServerConnection.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ export class ServerConnection {
9797
}
9898
}
9999

100-
getServerStatus = async (): Promise<ServerStatus> => {
100+
getServerStatus = async (timeout: number = 10000): Promise<ServerStatus> => {
101101
await this.lastServerStatusPromise
102-
this.lastServerStatusPromise = this.fetchServerStatus();
102+
this.lastServerStatusPromise = this.fetchServerStatus(timeout);
103103

104104
const status = await this.lastServerStatusPromise;
105105

@@ -114,12 +114,13 @@ export class ServerConnection {
114114
setTimeout(this.updateStatusLoop, 5000);
115115
}
116116

117-
private fetchServerStatus = async (): Promise<ServerStatus> => {
117+
private fetchServerStatus = async (timeout: number): Promise<ServerStatus> => {
118118
try {
119119
const res = await this.fetch(url.status, {
120120
headers: {
121121
'Content-Type': 'application/json'
122122
},
123+
signal: AbortSignal.timeout(timeout)
123124
});
124125

125126
if (res.status !== 200) {

0 commit comments

Comments
 (0)