Skip to content

Commit a9d3431

Browse files
committed
D-Tale remote timeout fix attempt
1 parent d4e33de commit a9d3431

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

‎backend/expressServer.mjs‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,13 @@ function cleanGoResponsePayload(payload = "") {
479479
}
480480
}
481481

482-
async function callGoEndpoint(topic, payload = {}) {
482+
async function callGoEndpoint(topic, payload = {}, options = {}) {
483483
if (!serviceState.go.port) {
484484
throw new Error("GO server is not running")
485485
}
486486
const url = `http://127.0.0.1:${serviceState.go.port}${topic.startsWith("/") ? "" : "/"}${topic}`
487-
const response = await axios.post(url, { message: JSON.stringify(payload) }, { headers: { "Content-Type": "application/json" }, timeout: 120000 })
487+
const timeoutMs = Number.isFinite(options?.timeoutMs) ? Number(options.timeoutMs) : 120000
488+
const response = await axios.post(url, { message: JSON.stringify(payload) }, { headers: { "Content-Type": "application/json" }, timeout: timeoutMs <= 0 ? 0 : timeoutMs })
488489
const data = response && response.data ? response.data : {}
489490
if (data.type === "toParse") {
490491
return cleanGoResponsePayload(data.response_message)
@@ -503,10 +504,22 @@ function parseDtalePort(webServerUrl) {
503504
}
504505
}
505506

506-
async function waitForDtaleReady(progressTopic, timeoutMs = 120000) {
507+
async function waitForDtaleReady(progressTopic, timeoutMs = 300000) {
507508
const start = Date.now()
508509
while (Date.now() - start < timeoutMs) {
509-
const progress = await callGoEndpoint(progressTopic, {})
510+
let progress = null
511+
try {
512+
progress = await callGoEndpoint(progressTopic, {}, { timeoutMs: 10000 })
513+
} catch (err) {
514+
console.warn("D-Tale progress polling warning:", err && err.message ? err.message : err)
515+
await new Promise((resolve) => setTimeout(resolve, 1000))
516+
continue
517+
}
518+
519+
if (typeof progress === "string") {
520+
progress = cleanGoResponsePayload(progress)
521+
}
522+
510523
if (progress && progress.web_server_url) {
511524
const remotePort = parseDtalePort(progress.web_server_url)
512525
if (remotePort) {
@@ -517,6 +530,15 @@ async function waitForDtaleReady(progressTopic, timeoutMs = 120000) {
517530
}
518531
}
519532
}
533+
534+
const progressPort = Number(progress && progress.port)
535+
if (Number.isFinite(progressPort) && progressPort > 0) {
536+
return {
537+
webServerUrl: `http://127.0.0.1:${progressPort}/`,
538+
remotePort: progressPort,
539+
name: (progress && progress.name) || "D-Tale"
540+
}
541+
}
520542
await new Promise((resolve) => setTimeout(resolve, 1000))
521543
}
522544
throw new Error("Timed out waiting for D-Tale web server to become ready")
@@ -561,9 +583,10 @@ expressApp.post("/exploratory/dtale/start", async (req, res) => {
561583

562584
const routeId = `${requestId}/${pageId}-${dataset.name}`
563585
await callGoEndpoint(`/removeId/${routeId}`, { dataset })
564-
const startDtalePromise = callGoEndpoint(`/exploratory/start_dtale/${routeId}`, { dataset })
586+
void callGoEndpoint(`/exploratory/start_dtale/${routeId}`, { dataset }, { timeoutMs: 0 }).catch((err) => {
587+
console.warn("D-Tale start request warning:", err && err.message ? err.message : err)
588+
})
565589
const dtaleInfo = await waitForDtaleReady(`/exploratory/progress/${routeId}`)
566-
await startDtalePromise
567590
serviceState.exploratory.dtale.sessions[requestId] = {
568591
requestId,
569592
pageId,

0 commit comments

Comments
 (0)