Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@pokdeep
Copy link
Contributor

@pokdeep pokdeep commented Sep 10, 2025

Proposed changes

Fixes #14742
Invoke terminate on all unsuccessful websocket candidates regardless of their readyState.
This change simplifies the cleanup logic and prevents the linked issue from occurring as the ws library handles the appropriate way to terminate the connection depending on the ready state.

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

//: # (The current main branch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against the v8 branch.)

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

Further comments

Instead of an error being thrown a debug message can be seen showing the socket has been closed
DEBUG webdriver: Could not connect to Bidi protocol at wss://10.166.109.168/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi: WebSocket was closed before the connection was established

[0-0] 2025-09-10T14:45:39.452Z INFO webdriver: Register BiDi handler for session with id 8be10657e9589a26aa22ea3b67d865ff
[0-0] 2025-09-10T14:45:39.452Z INFO webdriver: Connecting to webSocketUrl wss://privatedomain.co.uk/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi
[0-0] 2025-09-10T14:45:39.455Z DEBUG webdriver: Attempt to connect to webSocketUrl wss://privatedomain.co.uk/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi
[0-0] 2025-09-10T14:45:39.457Z DEBUG webdriver: Attempt to connect to webSocketUrl wss://10.166.106.101/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi
[0-0] 2025-09-10T14:45:39.458Z DEBUG webdriver: Attempt to connect to webSocketUrl wss://10.166.109.168/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi
[0-0] 2025-09-10T14:45:39.458Z DEBUG webdriver: Attempt to connect to webSocketUrl wss://10.166.101.206/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi
[0-0] 2025-09-10T14:45:39.550Z DEBUG webdriver: Could not connect to Bidi protocol at wss://10.166.106.101/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi: Unexpected server response: 404
[0-0] 2025-09-10T14:45:39.583Z INFO webdriver: Connected to Bidi protocol at wss://privatedomain.co.uk/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi
[0-0] 2025-09-10T14:45:39.583Z INFO webdriver: Connected to WebDriver Bidi interface at wss://privatedomain.co.uk/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi
[0-0] 2025-09-10T14:45:39.584Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.contextCreated"]}
[0-0] 2025-09-10T14:45:39.584Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["log.entryAdded","browsingContext.navigationStarted"]}
[0-0] 2025-09-10T14:45:39.585Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[1319 bytes]>, contexts: undefined }
[0-0] 2025-09-10T14:45:39.585Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted","browsingContext.fragmentNavigated","network.responseCompleted","network.beforeRequestSent","network.fetchError"]}
[0-0] 2025-09-10T14:45:39.585Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.userPromptOpened"]}
[0-0] 2025-09-10T14:45:39.585Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted"]}
[0-0] 2025-09-10T14:45:39.585Z INFO webdriver: COMMAND getWindowHandle()
[0-0] 2025-09-10T14:45:39.586Z INFO webdriver: BIDI COMMAND browsingContext.getTree {}
[0-0] 2025-09-10T14:45:39.586Z INFO webdriver: [GET] https://privatedomain.co.uk/wd/hub/session/8be10657e9589a26aa22ea3b67d865ff/window
[0-0] 2025-09-10T14:45:39.587Z DEBUG webdriver: Could not connect to Bidi protocol at wss://10.166.109.168/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi: WebSocket was closed before the connection was established
[0-0] 2025-09-10T14:45:39.587Z DEBUG webdriver: Could not connect to Bidi protocol at wss://10.166.101.206/session/8be10657e9589a26aa22ea3b67d865ff/se/bidi: WebSocket was closed before the connection was established

Reviewers: @webdriverio/project-committers

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 10, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

One comment, otherwise happy to go with this.


const socketsToCleanup = wsInfo ? websockets.filter((_, index) => wsInfo.index !== index) : websockets
for (const socket of socketsToCleanup) {
socket.removeAllListeners()
Copy link
Member

Choose a reason for hiding this comment

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

Should we keep this? It doesn't seem to be called within terminate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've had a look into it and I can't find a reason to keep it.
I did spot in the FAQs of ws readme examples of terminating the websocket and they don't have any logic on removing listeners tied to it

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 14, 2025

Open in StackBlitz

create-wdio

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

eslint-plugin-wdio

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

@wdio/allure-reporter

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

@wdio/appium-service

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

@wdio/browser-runner

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

@wdio/browserstack-service

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

@wdio/cli

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

@wdio/concise-reporter

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

@wdio/config

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

@wdio/cucumber-framework

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

@wdio/dot-reporter

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

@wdio/firefox-profile-service

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

@wdio/globals

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

@wdio/jasmine-framework

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

@wdio/json-reporter

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

@wdio/junit-reporter

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

@wdio/lighthouse-service

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

@wdio/local-runner

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

@wdio/logger

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

@wdio/mocha-framework

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

@wdio/protocols

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

@wdio/repl

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

@wdio/reporter

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

@wdio/runner

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

@wdio/sauce-service

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

@wdio/shared-store-service

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

@wdio/smoke-test-cjs-service

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

@wdio/smoke-test-reporter

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

@wdio/smoke-test-service

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

@wdio/spec-reporter

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

@wdio/static-server-service

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

@wdio/sumologic-reporter

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

@wdio/testingbot-service

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

@wdio/types

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

@wdio/utils

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

@wdio/webdriver-mock-service

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

@wdio/xvfb

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

webdriver

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

webdriverio

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

commit: 24dccd6

@christian-bromann
Copy link
Member

@pokdeep can you check , it seems like the failing e2e test is connected to this change.

@christian-bromann
Copy link
Member

Actually I see these tests failing in main. So we have to fix this separately. Will go ahead and merge. Thanks for the contribution.

@christian-bromann christian-bromann merged commit e5b761a into webdriverio:main Nov 14, 2025
57 of 59 checks passed
@christian-bromann christian-bromann added the PR: Bug Fix 🐛 PRs that contain bug fixes label Nov 14, 2025
@wdio-bot
Copy link
Contributor

Hey pokdeep 👋

Thank you for your contribution to WebdriverIO! Your pull request has been marked as an "Expensable" contribution.

We've sent you an email with further instructions on how to claim your expenses from our development fund.
⚠️ You seemed to have committed using an email address ending up with @users.noreply.github.com, if you don't receive the email please feel free to reach out to us at expense@webdriver.io or in the contributing channel on Discord.

We are looking forward to more contributions from you in the future 🙌

Have a nice day,
The WebdriverIO Team 🤖

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

Labels

Expensable $25 💸 PR: Bug Fix 🐛 PRs that contain bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: ws causes webdriver crash when a websocket candidate errors after a different candidate has connected

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.