[machinelearningservices] Add retry logic to az ml ssh client websocket connection - #10259
[machinelearningservices] Add retry logic to az ml ssh client websocket connection#10259lavakumarrepala wants to merge 1 commit into
Conversation
The az ml job connect-ssh / connect-ssh-compute proxy (_ssh_connector.py) would immediately fail if the initial websocket handshake to the NBIP proxy/broker was refused or timed out, with no retry. SRE Agent investigation of SSH connection instability found this to be a remaining gap versus SSH clients such as VS Code Remote-SSH, which do retry the initial connection and see meaningfully better long-duration connection stats. Add _connect_with_retry(), an async context manager that retries the initial websocket connection with exponential backoff + jitter (configurable via AZUREML_SSH_CONNECT_MAX_RETRIES, AZUREML_SSH_CONNECT_RETRY_BASE_DELAY_SECONDS, AZUREML_SSH_CONNECT_RETRY_MAX_DELAY_SECONDS env vars) on transient failures (OSError, TimeoutError, websocket handshake/connection-closed errors), then re-raises once retries are exhausted. Once the tunnel is open and actively relaying SSH bytes we do not attempt a silent reconnect: this tunnel carries the raw SSH transport, so a new websocket connection cannot resume an in-flight SSH session. Recovering from mid-session drops requires server-side session continuity, tracked separately (NBIP rearchitecture work item).
|
Hi lavakumarrepala, |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
The new retry delay computation and env var handling can yield invalid sleep durations (and exceed the configured max delay), which can break retries under certain configurations.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR improves resiliency of az ml job connect-ssh (and compute instance connect-ssh) by adding retry logic around the initial WebSocket tunnel establishment in _ssh_connector.py, addressing transient proxy/broker handshake failures without attempting mid-session reconnects.
Changes:
- Introduces an async context manager
_connect_with_retry()to retry initial WebSocket connections with exponential backoff + jitter on retryable connect-time exceptions. - Adds env var configuration for retry count and backoff parameters (
AZUREML_SSH_CONNECT_MAX_RETRIES,...BASE_DELAY_SECONDS,...MAX_DELAY_SECONDS). - Switches the SSH tunnel setup to use
_connect_with_retry()instead of callingwebsockets.client.connect()directly.
File summaries
| File | Description |
|---|---|
| src/machinelearningservices/azext_mlv2/manual/custom/_ssh_connector.py | Adds a retrying WebSocket connect wrapper and uses it for the SSH-over-WebSocket tunnel. |
Review details
Suppressed comments (1)
src/machinelearningservices/azext_mlv2/manual/custom/_ssh_connector.py:103
delayis clamped tomax_delaybefore adding jitter, so the actual sleep can exceedAZUREML_SSH_CONNECT_RETRY_MAX_DELAY_SECONDSby up tobase_delay. Ifmax_delayis meant to be a hard cap, clamp after applying jitter.
delay = min(max_delay, base_delay * (2 ** (attempt - 1))) + random.uniform(0, base_delay)
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| max_retries = _get_int_env("AZUREML_SSH_CONNECT_MAX_RETRIES", 5) | ||
| base_delay = _get_float_env("AZUREML_SSH_CONNECT_RETRY_BASE_DELAY_SECONDS", 1.0) | ||
| max_delay = _get_float_env("AZUREML_SSH_CONNECT_RETRY_MAX_DELAY_SECONDS", 30.0) |
🤖 PR Validation — ️✔️ All clear
Summary
�z ml job connect-ssh (and connect-ssh for compute instances) proxies SSH traffic over a websocket tunnel via _ssh_connector.py. Today, if the initial websocket handshake to the NBIP proxy/broker is refused or times out, the client fails immediately with no retry.
SRE Agent investigation of SSH connection instability (ADO work item https://msdata.visualstudio.com/Vienna/_workitems/edit/5533560/) identified this as a remaining client-side gap: backend forwarder/broker stability fixes already improved connection duration stats, but the az ml SSH client still lacks the retry behavior that SSH clients such as VS Code Remote-SSH have (which show meaningfully better long-duration connection stats as a result).
Change
Testing
Opening as draft for review/discussion before merge.