Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit c92a203

Browse files
committed
Fix instance-provision fetch until timeout
1 parent 34b8a50 commit c92a203

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

packages/server-core/src/networking/instance-provision/instance-provision.class.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,15 @@ export async function checkForDuplicatedAssignments({
320320
// it assumes the pod is unresponsive. Locally, it just waits half a second and tries again - if the local
321321
// instanceservers are rebooting after the last person left, we just need to wait a bit for them to start.
322322
// In production, it attempts to delete that pod via the K8s API client and tries again.
323+
let retry = true
323324
const responsivenessCheck = await Promise.race([
324325
new Promise<boolean>((resolve) => {
325326
setTimeout(() => {
326-
logger.warn(`Instanceserver at ${ipAddress} too long to respond, assuming it is unresponsive and killing`)
327+
retry = false
327328
resolve(false)
328329
}, config.server.instanceserverUnreachableTimeoutSeconds * 1000) // timeout after 2 seconds
329330
}),
330-
new Promise<boolean>((resolve) => {
331+
new Promise<boolean>(async (resolve) => {
331332
const options = {} as any
332333
let protocol = 'http://'
333334
if (!config.kubernetes.enabled) {
@@ -337,17 +338,21 @@ export async function checkForDuplicatedAssignments({
337338
})
338339
}
339340

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)
342345
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+
}
348351
})
349352
])
353+
350354
if (!responsivenessCheck) {
355+
logger.warn(`Instanceserver at ${ipAddress} too long to respond, assuming it is unresponsive and killing`)
351356
await app.service(instancePath).remove(assignResult.id)
352357
const k8DefaultClient = getState(ServerState).k8DefaultClient
353358
if (config.kubernetes.enabled)

0 commit comments

Comments
 (0)