@@ -627,23 +627,22 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
627627
628628 // try refresh if any of watched settings is changed.
629629 let needRefresh = false ;
630- let changedSentinel ;
631- let changedSentinelWatcher ;
630+ let changedSentinel : WatchedSetting | undefined ;
631+ let changedSentinelWatcher : SettingWatcher | undefined ;
632632 if ( this . #watchAll) {
633633 needRefresh = await this . #checkConfigurationSettingsChange( this . #kvSelectors) ;
634634 } else {
635635 for ( const watchedSetting of this . #sentinels. keys ( ) ) {
636636 const configurationSettingId : ConfigurationSettingId = { key : watchedSetting . key , label : watchedSetting . label , etag : this . #sentinels. get ( watchedSetting ) ?. etag } ;
637- const response = await this . #getConfigurationSetting( configurationSettingId , {
638- onlyIfChanged : true
639- } ) ;
640-
641- const watcher = this . #sentinels. get ( watchedSetting ) ;
642- if ( response ?. statusCode === 200 // created or changed
643- || ( response === undefined && watcher ?. etag !== undefined ) // deleted
644- ) {
637+ const response : GetConfigurationSettingResponse | undefined
638+ = await this . #getConfigurationSetting( configurationSettingId , { onlyIfChanged : true } ) ;
639+
640+ const watcher : SettingWatcher = this . #sentinels. get ( watchedSetting ) ! ; // watcher should always exist for sentinels
641+ const isDeleted = response === undefined && watcher . etag !== undefined ; // previously existed, now deleted
642+ const isChanged = response && response . statusCode === 200 && watcher . etag !== response . etag ; // etag changed
643+ if ( isDeleted || isChanged ) {
645644 changedSentinel = watchedSetting ;
646- changedSentinelWatcher = watcher ;
645+ changedSentinelWatcher = { etag : isChanged ? response . etag : undefined } ;
647646 needRefresh = true ;
648647 break ;
649648 }
@@ -655,7 +654,11 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
655654 await adapter . onChangeDetected ( ) ;
656655 }
657656 await this . #loadSelectedKeyValues( ) ;
658- this . #sentinels. set ( changedSentinel , changedSentinelWatcher ) ; // update the changed sentinel's watcher
657+
658+ if ( changedSentinel && changedSentinelWatcher ) {
659+ // update the changed sentinel's watcher after loading new values, this can ensure a failed refresh will retry on next refresh
660+ this . #sentinels. set ( changedSentinel , changedSentinelWatcher ) ;
661+ }
659662 }
660663
661664 this . #kvRefreshTimer. reset ( ) ;
0 commit comments