Skip to content

Detect local emulator connectivity failures - #200

Open
Mike Krüger (mkrueger) wants to merge 1 commit into
mainfrom
dev/mkrueger/fix-emulator-connectivity-detection
Open

Detect local emulator connectivity failures#200
Mike Krüger (mkrueger) wants to merge 1 commit into
mainfrom
dev/mkrueger/fix-emulator-connectivity-detection

Conversation

@mkrueger

Copy link
Copy Markdown
Collaborator

Summary

  • distinguish interactive Ctrl+C from emulator operation timeouts so failures are no longer silently discarded
  • enforce a deterministic timeout for local emulator connect and command operations
  • report unavailable emulator errors and return stale emulator sessions to the disconnected state
  • keep cloud sessions and ordinary command errors connected

Validation

  • dotnet build CosmosDBShell/CosmosDBShell.csproj --no-restore
  • dotnet build CosmosDBShell.Tests/CosmosDBShell.Tests.csproj --no-restore
  • 71 focused connectivity, command exception, and MCP token-source tests passed
  • manually verified that connecting to a stopped emulator reports the failure and returns to the offline prompt
  • git diff --check

Report unavailable emulator operations instead of silently treating timeouts as cancellation, and return stale emulator sessions to the disconnected state.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 throws TimeoutException but does not cancel the underlying ReadAccountAsync operation. 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 with CancelAfter(LocalEmulatorOperationTimeout) and pass that token into ReadAccountAsync instead of WaitAsync.
                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;
@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall line coverage in commit 1be8b36 in the dev/mkrueger/fix-emu... branch remains at 62%, unchanged from commit 0d21834 in the main branch.

Show a line coverage summary of the most impacted files.
File main 0d21834 dev/mkrueger/fix-emu... 1be8b36 +/-
D:\a\CosmosDBSh...s\PwdCommand.cs 100% 87% -13%
D:\a\CosmosDBSh...hellLocation.cs 89% 79% -10%
D:\a\CosmosDBSh...andException.cs 91% 91% 0%
D:\a\CosmosDBSh...lInterpreter.cs 62% 63% +1%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants