fix(browserstack-service): raise CLI download connect timeout to avoid 10s undici abort (SDK-6152)#6
Open
AakashHotchandani wants to merge 1 commit into
Open
Conversation
…d 10s undici abort (SDK-6152) Node's global fetch (undici) hard-codes a 10s connection-establishment timeout that is NOT overridable via AbortSignal. In constrained/containerised CI networks (e.g. Kubernetes pods) the TLS/TCP handshake to the SDK CLI binary CDN and the update_cli API can legitimately exceed 10s, so the download aborts with UND_ERR_CONNECT_TIMEOUT even though the endpoint is healthy. The error was logged only at debug level, so the run then exited silently with no results. - fetchWrapper._fetch accepts a `connectTimeoutMs` option and routes the request through a cached custom undici dispatcher (Agent / ProxyAgent) with the configured connect timeout. The default (no-option) path is unchanged. - requestToUpdateCLI and the binary download now use it (default 60s, overridable via BROWSERSTACK_CLI_CONNECT_TIMEOUT_MS), plus retry-with-backoff on transient connection failures. - CLI setup failures are surfaced at warn instead of debug so they are visible. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dandonarahul2002
approved these changes
Jun 2, 2026
osho-20
approved these changes
Jun 2, 2026
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.
SDK-6152 — SDK CLI binary download times out after exactly 10s in containerised CI
Problem
@wdio/browserstack-servicev9 downloads the SDK CLI binary (and callsupdate_cli) via Node's globalfetch(undici). Undici hard-codes a 10s connection-establishment timeout that is not overridable viaAbortSignal. In constrained/containerised CI networks (the reported case: Kubernetes pods) the TLS/TCP handshake to the CDN /api.browserstack.comcan legitimately take longer than 10s, so the download aborts withUND_ERR_CONNECT_TIMEOUTeven though the endpoint is healthy. The failure was logged only atdebug, so the run then exited silently with no results.This matches the customer evidence exactly: a standalone
fetch()probe of the same URL succeeded (free event loop / fast connect), while the service's internal download died at exactly 10s.Fix
fetchWrapper._fetchnow accepts aconnectTimeoutMsoption and routes the request through a cached custom undici dispatcher (Agent/ProxyAgent) with the configured connect timeout. The default (no-option) path is unchanged (still globalfetch).requestToUpdateCLIand the binary download use it — default 60s, overridable viaBROWSERSTACK_CLI_CONNECT_TIMEOUT_MS— plus retry-with-backoff (3 attempts) on transient connection failures.warninstead ofdebugso they're no longer silent.Why a custom dispatcher (and not global fetch + dispatcher)
Global fetch uses Node's built-in undici; passing an
Agentfrom the package undici to it fails withUND_ERR_INVALID_ARG(version mismatch). Going throughundiciFetchfrom the package — the same pattern the existing proxy branch already uses — is the consistent, safe choice.Verification
Against the real modified
fetchWrapper.ts, using a local TCP server that accepts the socket but never completes TLS (deterministic stalled connect):UND_ERR_CONNECT_TIMEOUT@ 10,541ms (reproduces the bug)connectTimeoutMs: 2000connectTimeoutMs: 6000→ the connect timeout now tracks the configured value instead of the hard 10s ceiling.
Unit tests:
packages/wdio-browserstack-service/tests/cli/cliUtils.test.ts— 40/40 pass (updatedrequestToUpdateCLItests to the new_fetchboundary + 3 newfetchWithRetrytests). ESLint clean on changed files;fetchWrapper.tstype-checks clean.Note (server/CDN side, out of scope here)
The reported version trigger (binary
1.34.0OK →1.34.1/1.34.2fail) is most plausibly CloudFront cache warmth / object-size changes around the new release pushing connect/transfer past the old 10s ceiling. This PR removes the client-side cliff; the CDN behaviour for new releases is worth a separate look.🤖 Generated with Claude Code