Skip to content

Add configurable connection timeout as a VS Code setting for instrument connections - #315

Merged
suribabu-ganti merged 8 commits into
release/v1.5.2from
task/TSP-822-UX-improvements-when-connecting-to-instrument-Part-2
Aug 27, 2026
Merged

suribabu-ganti merged 8 commits into
release/v1.5.2from
task/TSP-822-UX-improvements-when-connecting-to-instrument-Part-2

Conversation

@suribabu-ganti

Copy link
Copy Markdown
Contributor

Users can now set connectionTimeout to bound how long a connection attempt may run. If it doesn't complete in time, the attempt is cancelled and the user is notified with a warning message.

  • Added a new setting tsp.connectionTimeout (number, seconds, default 30, 0 disables it) so users can configure how long a connection attempt may run before being aborted.
  • Added Connection.combineCancellationTokens(), a helper that merges multiple vscode.CancellationTokens into one that fires when any of them cancels. This lets the timeout and the user's manual "Cancel" click in the progress notification share the same cancellation path already used inside runConnectFlow.
  • Added runConnectFlowWithTimeout(), which:
    Reads tsp.connectionTimeout from configuration.
    If 0/invalid, calls runConnectFlow unchanged (no timeout).
    Otherwise starts a setTimeout for that many seconds; if it fires, logs a warning, and shows warning message to notify the user the connection timed out.

Wrap runConnectFlow with runConnectFlowWithTimeout, which reads the tsp.connectionTimeout setting and cancels an in-progress connection attempt if it doesn't complete in time, notifying the user with a warning message.

Add Connection.combineCancellationTokens() to merge the existing progress-cancellation token with a timeout-driven token, so a timeout is handled through the same cancellation path already used for user-initiated cancellation (terminates the background process and restores the original status).

A timeout of 0 (or an invalid value) disables the timeout entirely.
…tionTokens now returns a disposable that removes its listeners once a connect() attempt finishes, instead of leaving them registered indefinitely

- Add a safe process-termination helper (terminateBackgroundProcess) that only clears/kills _background_process if it's still the same process instance, preventing a stale timeout/callback from terminating a newer background process

- Ensure proper timeout vs user cancellation handling: both paths now go through the same cancellation flow, reliably terminating the active background process and restoring the prior connection status
@suribabu-ganti
suribabu-ganti requested a review from a team as a code owner August 25, 2026 14:35
Add CancelReason ("user" | "timeout") tracked in runConnectFlowWithTimeout and passed into runConnectFlow, so cancellation logs correctly report "cancelled by user" vs "cancelled due to timeout" instead of a single generic message.

Use a first-cancellation-wins rule: cancelReason is set by whichever source (user cancel or timeout) fires first, with the user-cancellation listener registered before combineCancellationTokens() so it always runs before the forwarding listener that triggers runConnectFlow's handler. This avoids an ambiguous reason when both fire nearly simultaneously.
Forward status updates when an existing connection is merged by address and type, ensuring the instrument explorer icon transitions correctly from Connecting to Connected or Active instead of remaining stuck on the initial status.
@suribabu-ganti
suribabu-ganti merged commit d9f530a into release/v1.5.2 Aug 27, 2026
14 checks passed
@suribabu-ganti
suribabu-ganti deleted the task/TSP-822-UX-improvements-when-connecting-to-instrument-Part-2 branch August 27, 2026 05:02
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