File tree 1 file changed +25
-4
lines changed
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 {
23
23
return host . endsWith ( '.cloudworkstations.dev' ) ;
24
24
}
25
25
26
+ const pingQueue : { [ name : string ] : boolean } = { } ;
27
+ const MAX_PING_RETRIES = 10 ;
28
+
26
29
/**
27
30
* Makes a fetch request to the given server.
28
31
* Mostly used for forwarding cookies in Firebase Studio.
29
32
* @public
30
33
*/
31
34
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 ;
36
57
}
You can’t perform that action at this time.
0 commit comments