Skip to content

Commit 8229a9f

Browse files
authored
Merge 12759bc into 799de59
2 parents 799de59 + 12759bc commit 8229a9f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

packages/util/src/url.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,35 @@ export function isCloudWorkstation(host: string): boolean {
2323
return host.endsWith('.cloudworkstations.dev');
2424
}
2525

26+
const pingQueue: { [name: string]: boolean } = {};
27+
const MAX_PING_RETRIES = 10;
28+
2629
/**
2730
* Makes a fetch request to the given server.
2831
* Mostly used for forwarding cookies in Firebase Studio.
2932
* @public
3033
*/
3134
export async function pingServer(endpoint: string): Promise<boolean> {
32-
const result = await fetch(endpoint, {
33-
credentials: 'include'
34-
});
35-
return result.ok;
35+
if (pingQueue[endpoint]) {
36+
return Promise.resolve(false);
37+
}
38+
pingQueue[endpoint] = true;
39+
function waitFor(ms: number) {
40+
return new Promise((resolve, reject) => {
41+
setTimeout(resolve);
42+
});
43+
}
44+
for (let i = 0; i < MAX_PING_RETRIES; i++) {
45+
try {
46+
await waitFor(i * 1000);
47+
const result = await fetch(endpoint, {
48+
credentials: 'include'
49+
});
50+
if (result.ok) {
51+
return result.ok;
52+
}
53+
} catch {}
54+
}
55+
delete pingQueue[endpoint];
56+
return false;
3657
}

0 commit comments

Comments
 (0)