Skip to content

Commit 76c4bed

Browse files
jeet1995Copilot
andcommitted
Fix background database account refresh stopping in multi-writer accounts
In multi-writer accounts, refreshLocationPrivateAsync() stops the background refresh timer when shouldRefreshEndpoints() returns false. This means topology changes (e.g., multi-write to single-write transitions) go undetected until the next explicit refresh trigger. The .NET SDK (azure-cosmos-dotnet-v3) correctly continues the background refresh loop unconditionally - the loop only stops when canRefreshInBackground is explicitly false, not when shouldRefreshEndpoints returns false. This fix adds startRefreshLocationTimerAsync() to the else-branch of refreshLocationPrivateAsync(), ensuring the background timer always reschedules itself regardless of whether endpoints currently need refreshing. Without this fix, after a multi-write -> single-write -> multi-write transition, reads remain stuck on the primary region because the SDK never re-reads account metadata to learn about the restored multi-write topology. Related: PR #6139 (point #4 in description acknowledged this bug) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d3ede3b commit 76c4bed

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/GlobalEndpointManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ private Mono<Void> refreshLocationPrivateAsync(DatabaseAccount databaseAccount)
245245
return Mono.empty();
246246
} else {
247247
logger.debug("shouldRefreshEndpoints: false, nothing to do.");
248+
249+
// Even when no endpoint refresh is needed right now, we must keep the
250+
// background refresh timer running so that future topology changes
251+
// (e.g., multi-write <-> single-write transitions) are detected.
252+
// This aligns with the .NET SDK behavior where the background loop
253+
// continues unconditionally as long as the client is alive.
254+
if (!this.refreshInBackground.get()) {
255+
this.startRefreshLocationTimerAsync();
256+
}
257+
248258
this.isRefreshing.set(false);
249259
return Mono.empty();
250260
}

0 commit comments

Comments
 (0)