Skip to content

Commit a85ae2e

Browse files
Fix exponential backoff logic and ping race condition in desktop startup
Addresses code review feedback on the adaptive polling mechanism in startDesktopMode(): > Fix exponential backoff to cap at 1000ms instead of cycling back to 100ms > Move pingInProgress flag before the async pingServer() call to prevent race conditions > Update showErrorDialog to use clearTimeout consistent with setTimeout-based scheduling
1 parent bf654af commit a85ae2e

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

runtime/src/js/pgadmin.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function showErrorDialog(intervalID) {
163163
if(!splashWindow.isVisible()) {
164164
return;
165165
}
166-
clearInterval(intervalID);
166+
clearTimeout(intervalID);
167167
splashWindow.close();
168168

169169
new BrowserWindow({
@@ -312,6 +312,7 @@ function startDesktopMode() {
312312
return;
313313
}
314314

315+
pingInProgress = true;
315316
pingServer().then(() => {
316317
pingInProgress = false;
317318
splashWindow.webContents.executeJavaScript('document.getElementById(\'loader-text-status\').innerHTML = \'pgAdmin 4 started\';', true);
@@ -345,17 +346,10 @@ function startDesktopMode() {
345346
}
346347

347348
pingIntervalID = setTimeout(performPing, currentPingInterval);
348-
if (currentPingInterval === 1000) {
349-
currentPingInterval = 100;
350-
} else {
351-
currentPingInterval = currentPingInterval * 2;
352-
if (currentPingInterval > 1000) {
353-
currentPingInterval = 1000;
354-
}
349+
if (currentPingInterval < 1000) {
350+
currentPingInterval = Math.min(currentPingInterval * 2, 1000);
355351
}
356352
});
357-
358-
pingInProgress = true;
359353
}
360354

361355
performPing();

0 commit comments

Comments
 (0)