@@ -237,6 +237,7 @@ export abstract class IntegrationBase<
237237 requestSessionSyncForUsecase ( syncReqUsecase : SyncReqUsecase ) : void {
238238 this . _syncRequestsPerFailedUsecase . add ( syncReqUsecase ) ;
239239 }
240+ private refreshDueToExpirationRequested = false ;
240241 private static readonly requestExceptionLimit = 5 ;
241242 private requestExceptionCount = 0 ;
242243
@@ -338,9 +339,14 @@ export abstract class IntegrationBase<
338339 private missingExpirityReported = false ;
339340 @gate ( )
340341 protected async refreshSessionIfExpired ( scope ?: LogScope ) : Promise < void > {
341- if ( this . _session ?. expiresAt != null && this . _session . expiresAt < new Date ( ) ) {
342+ if (
343+ ! this . refreshDueToExpirationRequested &&
344+ this . _session ?. expiresAt != null &&
345+ this . _session . expiresAt < new Date ( )
346+ ) {
342347 // The current session is expired, so get the latest from the cloud and refresh if needed
343348 try {
349+ this . refreshDueToExpirationRequested = true ;
344350 await this . syncCloudConnection ( 'connected' , true ) ;
345351 } catch ( ex ) {
346352 Logger . error ( ex , scope ) ;
@@ -430,6 +436,9 @@ export abstract class IntegrationBase<
430436
431437 this . _session = session ?? null ;
432438 this . smoothifyRequestExceptionCount ( ) ;
439+ if ( this . _session ?. expiresAt == null || this . _session . expiresAt > new Date ( ) ) {
440+ this . refreshDueToExpirationRequested = false ;
441+ }
433442
434443 if ( session != null ) {
435444 await this . container . storage . storeWorkspace ( this . connectedKey , true ) ;
0 commit comments