@@ -445,6 +445,7 @@ class AuthManager(private val cs: CoroutineScope) : Disposable {
445445 autoRefreshWaitingJob?.cancel(CancellationException (message, null ))
446446 autoRefreshJob?.cancel(CancellationException (message, null ))
447447 } catch (e: Throwable ) {
448+ Log .warnWithException(logger, e, " autoRefreshJob failed to stop {}" , e)
448449 ErrorReporter .getInstance().reportError(" AuthManager.stopAutoRefresh" , e)
449450 }
450451 }
@@ -454,6 +455,7 @@ class AuthManager(private val cs: CoroutineScope) : Disposable {
454455 Log .log(logger::trace, " starting autoRefreshJob" )
455456 autoRefreshJob = startAutoRefreshJob(cs)
456457 } catch (e: Throwable ) {
458+ Log .warnWithException(logger, e, " autoRefreshJob failed to start {}" , e)
457459 ErrorReporter .getInstance().reportError(" AuthManager.startAutoRefresh" , e)
458460 }
459461 }
@@ -463,6 +465,7 @@ class AuthManager(private val cs: CoroutineScope) : Disposable {
463465 Log .log(logger::trace, " canceling autoRefreshJob.autoRefreshWaitingJob {}" , message)
464466 autoRefreshWaitingJob?.cancel(CancellationException (message, null ))
465467 } catch (e: Throwable ) {
468+ Log .warnWithException(logger, e, " autoRefreshJob.autoRefreshWaitingJob failed to stop {}" , e)
466469 ErrorReporter .getInstance().reportError(" AuthManager.cancelAutoRefreshWaitingJob" , e)
467470 }
468471 }
@@ -511,7 +514,11 @@ class AuthManager(private val cs: CoroutineScope) : Disposable {
511514 delay = 10 .minutes
512515 } else if (credentials == null ) {
513516 // if credentials not found it will probably be created soon
514- Log .log(logger::trace, " ${coroutineContext[CoroutineName ]} credentials for account not found, waiting 1 minute" )
517+ Log .log(
518+ logger::trace,
519+ " ${coroutineContext[CoroutineName ]} credentials for account not found, waiting 1 minute. account {}" ,
520+ account
521+ )
515522 delay = 1 .minutes
516523 } else {
517524 Log .log(logger::trace, " ${coroutineContext[CoroutineName ]} found account and credentials {}" , account)
@@ -524,6 +531,11 @@ class AuthManager(private val cs: CoroutineScope) : Disposable {
524531
525532 if (expireIn == ZERO ) {
526533 // don't refresh if expireIn is zero it will e refreshed on authentication exception
534+ Log .log(
535+ logger::trace,
536+ " ${coroutineContext[CoroutineName ]} credentials expires in zero seconds,not refreshing, waiting 5 minutes. account {}" ,
537+ account
538+ )
527539 delay = 5 .minutes
528540 } else if (expireIn <= 1 .minutes) {
529541 Log .log(
@@ -561,7 +573,7 @@ class AuthManager(private val cs: CoroutineScope) : Disposable {
561573 if (timeSinceLastStatistics >= 1 .hours) {
562574 statisticsStartTime = now
563575 reportAuthPosthogEvent(
564- " AutoRefreshStats " , " AutoRefreshJob" , null , mapOf (
576+ " AutoRefreshStatistics " , " AutoRefreshJob" , null , mapOf (
565577 " period.minutes" to timeSinceLastStatistics.inWholeMinutes,
566578 " refresh.counter" to refreshCounter
567579 )
@@ -571,22 +583,31 @@ class AuthManager(private val cs: CoroutineScope) : Disposable {
571583
572584 if (refreshSuccess) {
573585 fireChange()
574- Log .log(logger::trace, " ${coroutineContext[CoroutineName ]} credentials for account refreshed {}" , account)
586+ Log .log(
587+ logger::trace,
588+ " ${coroutineContext[CoroutineName ]} credentials for account refreshed,waiting 5 minutes. account {}" ,
589+ account
590+ )
575591 // after successful refresh wait 5 minutes , the token should be valid for 15 minutes
576592 // it should also let the credential store save and refresh its caches if any.
577593 delay = 5 .minutes
578594 } else {
579- Log .log(logger::trace, " ${coroutineContext[CoroutineName ]} refresh failed, waiting 5 minutes" )
595+ Log .log(
596+ logger::trace,
597+ " ${coroutineContext[CoroutineName ]} refresh failed, waiting 5 minutes. account {}" ,
598+ account
599+ )
580600 delay = 5 .minutes
581601 }
582602 } else {
583603 delay =
584604 max(0L , (expireIn.inWholeMilliseconds - 1 .minutes.inWholeMilliseconds)).toDuration(DurationUnit .MILLISECONDS )
585605 Log .log(
586606 logger::trace,
587- " ${coroutineContext[CoroutineName ]} credentials for account expires in {}, waiting {}" ,
607+ " ${coroutineContext[CoroutineName ]} credentials for account expires in {}, waiting {}. account {} " ,
588608 expireIn,
589- delay
609+ delay,
610+ account
590611 )
591612 }
592613 }
@@ -610,6 +631,7 @@ class AuthManager(private val cs: CoroutineScope) : Disposable {
610631 }
611632
612633 } catch (e: CancellationException ) {
634+ Log .log(logger::trace, " ${coroutineContext[CoroutineName ]} git CancellationException {}" , e)
613635 throw e
614636 } catch (e: Throwable ) {
615637 Log .warnWithException(logger, e, " ${coroutineContext[CoroutineName ]} error in autoRefreshJob" )
@@ -618,7 +640,10 @@ class AuthManager(private val cs: CoroutineScope) : Disposable {
618640 }
619641 }
620642
621- Log .log(logger::trace, " job autoRefreshJob exited (this should happen on IDE shutdown or when replacing api client)" )
643+ Log .log(
644+ logger::trace,
645+ " ${coroutineContext[CoroutineName ]} job autoRefreshJob exited (this should happen on IDE shutdown or when replacing api client)"
646+ )
622647 }
623648 }
624649
0 commit comments