Skip to content

fix: resolve etxtbsy issue(file busy error) at spawn#15246

Merged
christian-bromann merged 4 commits into
webdriverio:mainfrom
shivamku-BS:SDK-5786-etxtbsy-fix
May 12, 2026
Merged

fix: resolve etxtbsy issue(file busy error) at spawn#15246
christian-bromann merged 4 commits into
webdriverio:mainfrom
shivamku-BS:SDK-5786-etxtbsy-fix

Conversation

@shivamku-BS
Copy link
Copy Markdown
Contributor

Proposed changes

Fixes a binary file busy (ETXTBSY/EBUSY) error that occurred when the BrowserStack CLI binary was being executed while a new version was being written to the same file path during spawn.

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

  • This change is solely for v9 and doesn't need to be back-ported
  • Back-ported PR at #XXXXX

Further comments

Reviewers: @webdriverio/project-committers

@shivamku-BS shivamku-BS requested a review from a team as a code owner May 12, 2026 04:20
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 12, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: shivamku-BS / name: shivamku-BS (a3696a6)

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 12, 2026

Greptile Summary

This PR fixes ETXTBSY/EBUSY errors that occurred when the BrowserStack CLI binary was being executed while a new version was written to the same path. It replaces direct-to-destination extraction with a PID-scoped temp-file + atomic-rename approach for binary zip entries, adds a pre-spawn isBinaryBusy probe to skip updates when the binary is locked, and wraps spawn in a retry loop for residual busy errors.

  • cliUtils.tsdownloadFileStream rewired to extract binaries into <name>.tmp.<pid>, chmod, then atomically rename; a zip-slip guard is added; writeStreamErrored flag prevents double-close on the error path.
  • index.tsstartCLI now drives a _spawnAndAwaitReady helper behind a retry loop; an idempotent settle guard prevents double-settlement; clean exits before "ready" now correctly reject instead of hanging.
  • constants.tsBINARY_BUSY_ERROR_CODES, MAX_SPAWN_RETRIES, SPAWN_RETRY_DELAY_MS extracted as constants.

Confidence Score: 3/5

The download/extraction path in cliUtils.ts has two open error paths that leave file descriptors unclosed and can crash the process; needs fixes before merging.

Two distinct defects exist in downloadFileStream: (1) when openReadStreamPromise throws for a binary entry, writeStream is created but never destroyed — the fd leaks and fsp.unlink on Windows will fail because the file is still open; (2) neither the binary nor the non-binary path attaches an 'error' handler to the piped readStream, so a decompression error during extraction fires an unhandled event and crashes the test session. The spawn-retry logic in index.ts and the atomic-rename approach in cliUtils.ts are otherwise well-structured.

packages/wdio-browserstack-service/src/cli/cliUtils.ts — specifically the openReadStreamPromise catch blocks in both binary and non-binary paths, and the missing readStream error handlers.

Important Files Changed

Filename Overview
packages/wdio-browserstack-service/src/cli/cliUtils.ts Core of the ETXTBSY fix: adds PID-scoped temp-file extraction, atomic rename, zip-slip guard, and isBinaryBusy probe. Two error paths in downloadFileStream leave file descriptors open when openReadStreamPromise rejects, and neither path attaches an error handler to the piped readStream.
packages/wdio-browserstack-service/src/cli/index.ts Adds spawn-retry loop with _spawnAndAwaitReady helper; uses idempotent settle to prevent double-settlement; handles synchronous spawn errors and clean-exit-before-ready. Logic is correct.
packages/wdio-browserstack-service/src/constants.ts Adds BINARY_BUSY_ERROR_CODES, MAX_SPAWN_RETRIES, and SPAWN_RETRY_DELAY_MS constants. No issues.
packages/wdio-browserstack-service/tests/cli/cliUtils.test.ts Removes the now-deleted binaryName parameter from the downloadFileStream test call; no new coverage for isBinaryBusy or the spawn-retry logic.

Reviews (4): Last reviewed commit: "fix(cli): zip-slip guard, directStream e..." | Re-trigger Greptile

Comment thread packages/wdio-browserstack-service/src/cli/index.ts
Comment thread packages/wdio-browserstack-service/src/cli/cliUtils.ts Outdated
Comment thread packages/wdio-browserstack-service/src/cli/cliUtils.ts
Comment thread packages/wdio-browserstack-service/src/cli/cliUtils.ts
Comment thread packages/wdio-browserstack-service/src/cli/cliUtils.ts
@shivamku-BS shivamku-BS changed the title fix: resolve etxtbsy issue in SDK fix: resolve etxtbsy issue(file busy error) at spawn May 12, 2026
Comment thread packages/wdio-browserstack-service/src/cli/cliUtils.ts
Comment thread packages/wdio-browserstack-service/src/cli/cliUtils.ts
…or bailout

Address review:
- Add zip-slip guard before extraction (BROWSERSTACK_BINARY_URL safety)
- Add 'error' listener on directStream for non-binary entries
- Add writeStreamErrored flag + early-return in close handler to prevent
  double zipfile.close() and ENOENT on chmod when stream errors

Co-authored-by: Claude <noreply@anthropic.com>
Comment thread packages/wdio-browserstack-service/src/cli/cliUtils.ts
Comment thread packages/wdio-browserstack-service/src/cli/cliUtils.ts
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 12, 2026

Open in StackBlitz

create-wdio

npm i https://pkg.pr.new/webdriverio/webdriverio/create-wdio@15246

eslint-plugin-wdio

npm i https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@15246

@wdio/allure-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@15246

@wdio/appium-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@15246

@wdio/browser-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@15246

@wdio/browserstack-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@15246

@wdio/cli

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@15246

@wdio/concise-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@15246

@wdio/config

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@15246

@wdio/cucumber-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@15246

@wdio/dot-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@15246

@wdio/firefox-profile-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@15246

@wdio/globals

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@15246

@wdio/jasmine-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@15246

@wdio/json-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@15246

@wdio/junit-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@15246

@wdio/lighthouse-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@15246

@wdio/local-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@15246

@wdio/logger

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@15246

@wdio/mocha-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@15246

@wdio/protocols

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@15246

@wdio/repl

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@15246

@wdio/reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@15246

@wdio/runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@15246

@wdio/sauce-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@15246

@wdio/shared-store-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@15246

@wdio/smoke-test-cjs-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@15246

@wdio/smoke-test-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@15246

@wdio/smoke-test-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@15246

@wdio/spec-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@15246

@wdio/static-server-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@15246

@wdio/sumologic-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@15246

@wdio/testingbot-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@15246

@wdio/types

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@15246

@wdio/utils

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@15246

@wdio/webdriver-mock-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@15246

@wdio/xvfb

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/xvfb@15246

webdriver

npm i https://pkg.pr.new/webdriverio/webdriverio/webdriver@15246

webdriverio

npm i https://pkg.pr.new/webdriverio/webdriverio@15246

commit: c0169af

@christian-bromann christian-bromann added the PR: Bug Fix 🐛 PRs that contain bug fixes label May 12, 2026
@christian-bromann christian-bromann merged commit 7b4013f into webdriverio:main May 12, 2026
112 of 113 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 PRs that contain bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants