@@ -299,22 +299,26 @@ function startDesktopMode() {
299299 let midTime1 = currentTime + ( connectionTimeout / 2 ) ;
300300 let midTime2 = currentTime + ( connectionTimeout * 2 / 3 ) ;
301301 let pingInProgress = false ;
302+ let currentPingInterval = 100 ;
302303
303- // ping pgAdmin server every 1 second .
304+ // ping pgAdmin server with adaptive polling .
304305 let pingStartTime = ( new Date ) . getTime ( ) ;
305- pingIntervalID = setInterval ( function ( ) {
306+
307+ function performPing ( ) {
306308 // If ping request is already send and response is not
307309 // received no need to send another request.
308- if ( pingInProgress )
310+ if ( pingInProgress ) {
311+ pingIntervalID = setTimeout ( performPing , currentPingInterval ) ;
309312 return ;
313+ }
310314
311315 pingServer ( ) . then ( ( ) => {
312316 pingInProgress = false ;
313317 splashWindow . webContents . executeJavaScript ( 'document.getElementById(\'loader-text-status\').innerHTML = \'pgAdmin 4 started\';' , true ) ;
314318 // Set the pgAdmin process object to misc
315319 misc . setProcessObject ( pgadminServerProcess ) ;
316320
317- clearInterval ( pingIntervalID ) ;
321+ clearTimeout ( pingIntervalID ) ;
318322 let appEndTime = ( new Date ) . getTime ( ) ;
319323 misc . writeServerLog ( '------------------------------------------' ) ;
320324 misc . writeServerLog ( 'Total time taken to ping pgAdmin4 server: ' + ( appEndTime - pingStartTime ) / 1000 + ' Sec' ) ;
@@ -329,6 +333,7 @@ function startDesktopMode() {
329333 // and stop pinging the server.
330334 if ( curTime >= endTime ) {
331335 showErrorDialog ( pingIntervalID ) ;
336+ return ;
332337 }
333338
334339 if ( curTime > midTime1 ) {
@@ -338,10 +343,22 @@ function startDesktopMode() {
338343 splashWindow . webContents . executeJavaScript ( 'document.getElementById(\'loader-text-status\').innerHTML = \'Almost there...\';' , true ) ;
339344 }
340345 }
346+
347+ 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+ }
355+ }
341356 } ) ;
342357
343358 pingInProgress = true ;
344- } , 1000 ) ;
359+ }
360+
361+ performPing ( ) ;
345362}
346363
347364// This function is used to hide the splash screen and create/launch
0 commit comments