You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Retry Cosmos container/database initialization on 404/1013 race - #60
Cosmos DB emulator (and occasionally the cloud service) can respond to a container/database read with 404 NotFound, substatus 1013 ('Collection is not yet available for read') for a short window right after it is created. This happens when two or more processes race to create the same database or container concurrently — common in local Aspire setups where multiple services/processors start simultaneously against the same emulator instance.
This crashed the host on startup (\DocumentStoreService.StartAsync\ -> \SubscriptionInitializer.InitializeAsync), e.g. observed in load-management's Processors project.
Fix
Added \CosmosRetryHelper\ with exponential backoff (1s -> 10s, up to 6 attempts) that retries only on the specific 404/1013 signature.
Applied it in \DocumentStoreInitializer\ (database creation), \DocumentInitializer\ (document container creation) and \SubscriptionInitializer\ (change-feed lease container creation).
Added unit tests covering: first-try success, retry-then-succeed, giving up after max attempts, and not retrying unrelated Cosmos exceptions.
Cosmos DB emulator (and occasionally the cloud service) can respond to a
container/database read with 404 NotFound, substatus 1013 ('Collection is
not yet available for read') for a short window right after it is created.
This happens when two or more processes race to create the same database
or container concurrently, which is common in local Aspire setups where
multiple services/processors start at the same time against the same
Cosmos DB emulator instance.
Add CosmosRetryHelper with exponential backoff (1s -> 10s, 6 attempts) and
use it in DocumentStoreInitializer, DocumentInitializer and
SubscriptionInitializer so that DocumentStoreService.StartAsync no longer
crashes the host on startup when this transient race occurs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The retry tests stop after three attempts, so neither this 10-second cap nor the default six-attempt policy is exercised. A regression here would still leave the suite green; add a default-policy failure test asserting six calls and delays of 1, 2, 4, 8, and 10 seconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Cosmos DB emulator (and occasionally the cloud service) can respond to a container/database read with 404 NotFound, substatus 1013 ('Collection is not yet available for read') for a short window right after it is created. This happens when two or more processes race to create the same database or container concurrently — common in local Aspire setups where multiple services/processors start simultaneously against the same emulator instance.
This crashed the host on startup (\DocumentStoreService.StartAsync\ -> \SubscriptionInitializer.InitializeAsync), e.g. observed in load-management's Processors project.
Fix
All 221 existing + new tests pass.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com