From bf654af617b5d9c1a2503fef3071b3d9a6a6d4ba Mon Sep 17 00:00:00 2001 From: dev-hari-prasad Date: Sun, 22 Mar 2026 00:02:48 +0530 Subject: [PATCH 1/2] Update pgadmin.js --- runtime/src/js/pgadmin.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/runtime/src/js/pgadmin.js b/runtime/src/js/pgadmin.js index 07bdb8d5498..d5af634e7c1 100644 --- a/runtime/src/js/pgadmin.js +++ b/runtime/src/js/pgadmin.js @@ -299,14 +299,18 @@ function startDesktopMode() { let midTime1 = currentTime + (connectionTimeout / 2); let midTime2 = currentTime + (connectionTimeout * 2 / 3); let pingInProgress = false; + let currentPingInterval = 100; - // ping pgAdmin server every 1 second. + // ping pgAdmin server with adaptive polling. let pingStartTime = (new Date).getTime(); - pingIntervalID = setInterval(function () { + + function performPing() { // If ping request is already send and response is not // received no need to send another request. - if (pingInProgress) + if (pingInProgress) { + pingIntervalID = setTimeout(performPing, currentPingInterval); return; + } pingServer().then(() => { pingInProgress = false; @@ -314,7 +318,7 @@ function startDesktopMode() { // Set the pgAdmin process object to misc misc.setProcessObject(pgadminServerProcess); - clearInterval(pingIntervalID); + clearTimeout(pingIntervalID); let appEndTime = (new Date).getTime(); misc.writeServerLog('------------------------------------------'); misc.writeServerLog('Total time taken to ping pgAdmin4 server: ' + (appEndTime - pingStartTime) / 1000 + ' Sec'); @@ -329,6 +333,7 @@ function startDesktopMode() { // and stop pinging the server. if (curTime >= endTime) { showErrorDialog(pingIntervalID); + return; } if (curTime > midTime1) { @@ -338,10 +343,22 @@ function startDesktopMode() { splashWindow.webContents.executeJavaScript('document.getElementById(\'loader-text-status\').innerHTML = \'Almost there...\';', true); } } + + pingIntervalID = setTimeout(performPing, currentPingInterval); + if (currentPingInterval === 1000) { + currentPingInterval = 100; + } else { + currentPingInterval = currentPingInterval * 2; + if (currentPingInterval > 1000) { + currentPingInterval = 1000; + } + } }); pingInProgress = true; - }, 1000); + } + + performPing(); } // This function is used to hide the splash screen and create/launch From a85ae2e2f0842ebe3293574ab6b7fa32ca9f0508 Mon Sep 17 00:00:00 2001 From: dev-hari-prasad Date: Thu, 26 Mar 2026 17:47:27 +0530 Subject: [PATCH 2/2] 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 --- runtime/src/js/pgadmin.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/runtime/src/js/pgadmin.js b/runtime/src/js/pgadmin.js index d5af634e7c1..d7769525678 100644 --- a/runtime/src/js/pgadmin.js +++ b/runtime/src/js/pgadmin.js @@ -163,7 +163,7 @@ function showErrorDialog(intervalID) { if(!splashWindow.isVisible()) { return; } - clearInterval(intervalID); + clearTimeout(intervalID); splashWindow.close(); new BrowserWindow({ @@ -312,6 +312,7 @@ function startDesktopMode() { return; } + pingInProgress = true; pingServer().then(() => { pingInProgress = false; splashWindow.webContents.executeJavaScript('document.getElementById(\'loader-text-status\').innerHTML = \'pgAdmin 4 started\';', true); @@ -345,17 +346,10 @@ function startDesktopMode() { } pingIntervalID = setTimeout(performPing, currentPingInterval); - if (currentPingInterval === 1000) { - currentPingInterval = 100; - } else { - currentPingInterval = currentPingInterval * 2; - if (currentPingInterval > 1000) { - currentPingInterval = 1000; - } + if (currentPingInterval < 1000) { + currentPingInterval = Math.min(currentPingInterval * 2, 1000); } }); - - pingInProgress = true; } performPing();