File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed
Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Original file line number Diff line number Diff 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 */
3134export 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}
You can’t perform that action at this time.
0 commit comments