Skip to content

Commit 7546618

Browse files
fix the bug that sentinel key etag is not updaed (#237)
1 parent a9a4ab1 commit 7546618

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/appConfigurationImpl.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -619,23 +619,22 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
619619

620620
// try refresh if any of watched settings is changed.
621621
let needRefresh = false;
622-
let changedSentinel;
623-
let changedSentinelWatcher;
622+
let changedSentinel: WatchedSetting | undefined;
623+
let changedSentinelWatcher: SettingWatcher | undefined;
624624
if (this.#watchAll) {
625625
needRefresh = await this.#checkConfigurationSettingsChange(this.#kvSelectors);
626626
} else {
627627
for (const watchedSetting of this.#sentinels.keys()) {
628628
const configurationSettingId: ConfigurationSettingId = { key: watchedSetting.key, label: watchedSetting.label, etag: this.#sentinels.get(watchedSetting)?.etag };
629-
const response = await this.#getConfigurationSetting(configurationSettingId, {
630-
onlyIfChanged: true
631-
});
632-
633-
const watcher = this.#sentinels.get(watchedSetting);
634-
if (response?.statusCode === 200 // created or changed
635-
|| (response === undefined && watcher?.etag !== undefined) // deleted
636-
) {
629+
const response: GetConfigurationSettingResponse | undefined
630+
= await this.#getConfigurationSetting(configurationSettingId, { onlyIfChanged: true });
631+
632+
const watcher: SettingWatcher = this.#sentinels.get(watchedSetting)!; // watcher should always exist for sentinels
633+
const isDeleted = response === undefined && watcher.etag !== undefined; // previously existed, now deleted
634+
const isChanged = response && response.statusCode === 200 && watcher.etag !== response.etag; // etag changed
635+
if (isDeleted || isChanged) {
637636
changedSentinel = watchedSetting;
638-
changedSentinelWatcher = watcher;
637+
changedSentinelWatcher = { etag: isChanged ? response.etag : undefined };
639638
needRefresh = true;
640639
break;
641640
}
@@ -647,7 +646,11 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
647646
await adapter.onChangeDetected();
648647
}
649648
await this.#loadSelectedKeyValues();
650-
this.#sentinels.set(changedSentinel, changedSentinelWatcher); // update the changed sentinel's watcher
649+
650+
if (changedSentinel && changedSentinelWatcher) {
651+
// update the changed sentinel's watcher after loading new values, this can ensure a failed refresh will retry on next refresh
652+
this.#sentinels.set(changedSentinel, changedSentinelWatcher);
653+
}
651654
}
652655

653656
this.#kvRefreshTimer.reset();

0 commit comments

Comments
 (0)