Detect local emulator connectivity failures - #200
Open
Mike Krüger (mkrueger) wants to merge 1 commit into
Open
Conversation
Report unavailable emulator operations instead of silently treating timeouts as cancellation, and return stale emulator sessions to the disconnected state.
Mike Krüger (mkrueger)
requested review from
a team
and
a lite review from Copilot
August 26, 2026 11:47
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the shell’s handling of local Cosmos DB emulator outages by making emulator connectivity failures observable and deterministic, and by ensuring the shell transitions back to a disconnected/offline state on emulator connectivity failures (without impacting cloud sessions).
Changes:
- Added deterministic timeouts for local emulator connect and command execution, and differentiated user Ctrl+C cancellation from emulator timeouts.
- Introduced connectivity-failure detection (
CommandException.IsConnectivityFailure) and used it to disconnect only local emulator sessions after connectivity-related failures. - Updated client options for emulator sessions (shorter request timeout) and added test coverage + changelog entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs | Adds emulator-specific operation timeout logic, emulator-only disconnect behavior after connectivity failures, and emulator-specific client request timeout. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/CommandException.cs | Adds IsConnectivityFailure helper to classify connectivity-related exceptions (including nested exceptions). |
| CosmosDBShell.Tests/Shell/ExecuteCommandExceptionTests.cs | Adds tests validating connectivity-failure classification for CosmosException statuses and nested HttpRequestException. |
| CosmosDBShell.Tests/CommandTests/ConnectCommandTests.cs | Adds tests for emulator request timeout configuration and emulator-only disconnect behavior after connectivity failures. |
| CHANGELOG.md | Documents the emulator outage detection and state transition behavior change. |
Suppressed comments (1)
CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs:953
- The
ReadAccountAsync(...).WaitAsync(LocalEmulatorOperationTimeout, token)timeout path throwsTimeoutExceptionbut does not cancel the underlyingReadAccountAsyncoperation. That leaves the request running in the background even after the client is disposed in the catch block, which can surface delayed failures and adds avoidable work. Use a linked CTS withCancelAfter(LocalEmulatorOperationTimeout)and pass that token intoReadAccountAsyncinstead ofWaitAsync.
var readAccountTask = ReadAccountAsync(client, token);
keyProps = isEmulator
? await readAccountTask.WaitAsync(LocalEmulatorOperationTimeout, token)
: await readAccountTask;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+440
to
+443
| var commandTask = this.RunCommandAsync(state, command, token); | ||
| state = isLocalEmulatorOperation | ||
| ? await commandTask.WaitAsync(LocalEmulatorOperationTimeout, token) | ||
| : await commandTask; |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Validation
dotnet build CosmosDBShell/CosmosDBShell.csproj --no-restoredotnet build CosmosDBShell.Tests/CosmosDBShell.Tests.csproj --no-restoreofflinepromptgit diff --check