@@ -320,14 +320,15 @@ export async function checkForDuplicatedAssignments({
320
320
// it assumes the pod is unresponsive. Locally, it just waits half a second and tries again - if the local
321
321
// instanceservers are rebooting after the last person left, we just need to wait a bit for them to start.
322
322
// In production, it attempts to delete that pod via the K8s API client and tries again.
323
+ let retry = true
323
324
const responsivenessCheck = await Promise . race ( [
324
325
new Promise < boolean > ( ( resolve ) => {
325
326
setTimeout ( ( ) => {
326
- logger . warn ( `Instanceserver at ${ ipAddress } too long to respond, assuming it is unresponsive and killing` )
327
+ retry = false
327
328
resolve ( false )
328
329
} , config . server . instanceserverUnreachableTimeoutSeconds * 1000 ) // timeout after 2 seconds
329
330
} ) ,
330
- new Promise < boolean > ( ( resolve ) => {
331
+ new Promise < boolean > ( async ( resolve ) => {
331
332
const options = { } as any
332
333
let protocol = 'http://'
333
334
if ( ! config . kubernetes . enabled ) {
@@ -337,17 +338,21 @@ export async function checkForDuplicatedAssignments({
337
338
} )
338
339
}
339
340
340
- fetch ( protocol + ipAddress , options )
341
- . then ( ( result ) => {
341
+ // try fetching several times until it works, or timeout
342
+ while ( retry ) {
343
+ try {
344
+ await fetch ( protocol + ipAddress , options )
342
345
resolve ( true )
343
- } )
344
- . catch ( ( err ) => {
345
- logger . error ( err )
346
- resolve ( false )
347
- } )
346
+ } catch ( e ) {
347
+ // wait and try again
348
+ await new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( null ) , 500 ) )
349
+ }
350
+ }
348
351
} )
349
352
] )
353
+
350
354
if ( ! responsivenessCheck ) {
355
+ logger . warn ( `Instanceserver at ${ ipAddress } too long to respond, assuming it is unresponsive and killing` )
351
356
await app . service ( instancePath ) . remove ( assignResult . id )
352
357
const k8DefaultClient = getState ( ServerState ) . k8DefaultClient
353
358
if ( config . kubernetes . enabled )
0 commit comments