Skip to content

[🐛 Bug]: ConnectionFailedException: JdkWebSocket initial request execution error #2850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
IlyaUk opened this issue May 30, 2025 · 8 comments · Fixed by #2855
Closed

[🐛 Bug]: ConnectionFailedException: JdkWebSocket initial request execution error #2850

IlyaUk opened this issue May 30, 2025 · 8 comments · Fixed by #2855

Comments

@IlyaUk
Copy link

IlyaUk commented May 30, 2025

What happened?

An attempt to upgrade Selenium hub and Chrome nodes from version 4.25.0-20240922 to the latest ones shows that there is an error related to CDP - ConnectionFailedException: JdkWebSocket initial request execution error.
The issue is reproducible starting from 4.26.0-20241101 till the latest versions: 4.33.0-20250525.
The only one workaround to avoid the issue - set Selenium flag --enable-cdp false for Chrome nodes and disable all tests that use CDP features.

Command used to start Selenium Grid with Docker (or Kubernetes)

version: "3"
services:
  selenium-hub:
    image: selenium/hub:4.32.0-20250505
    container_name: selenium-hub
    ports:
      - "4444:4444"
      - "4443:4443"
      - "4442:4442"
    environment:
      - SE_ENABLE_TRACING=false
    healthcheck:
      test: "/opt/bin/check-grid.sh --host 0.0.0.0 --port 4444"
      interval: "15s"
      timeout: "30s"
      retries: 5
    restart: always

  chrome:
    image: selenium/node-chrome:4.32.0-20250505
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_VNC_NO_PASSWORD=1
      - SE_SCREEN_WIDTH=1600
      - SE_SCREEN_HEIGHT=900
      - SE_NODE_MAX_SESSIONS=1
      - SE_NODE_MAX_INSTANCES=1
      - SE_NODE_GRID_URL=http://${host}:4444
      - SE_OPTS=--enable-managed-downloads true --enable-cdp true
      - SE_ENABLE_TRACING=false
      - JAVA_OPTS=-Djava.net.preferIPv4Stack=true
    restart: always
    deploy:
      mode: replicated
      replicas: 8

Relevant log output

Caused by: org.openqa.selenium.remote.http.ConnectionFailedException: JdkWebSocket initial request execution error
Build info: version: '4.32.0', revision: 'd17c8aa950'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.8.0-1024-aws', java.version: '17.0.5'
Driver info: driver.version: unknown
	at org.openqa.selenium.remote.http.jdk.JdkHttpClient.openSocket(JdkHttpClient.java:253)
	at org.openqa.selenium.devtools.Connection.<init>(Connection.java:89)
	at org.openqa.selenium.devtools.SeleniumCdpConnection.<init>(SeleniumCdpConnection.java:36)
	at org.openqa.selenium.devtools.SeleniumCdpConnection.lambda$create$2(SeleniumCdpConnection.java:103)
	at java.base/java.util.Optional.map(Optional.java:260)
	at org.openqa.selenium.devtools.SeleniumCdpConnection.create(SeleniumCdpConnection.java:103)
	at org.openqa.selenium.devtools.SeleniumCdpConnection.create(SeleniumCdpConnection.java:49)
	at org.openqa.selenium.devtools.DevToolsProvider.getImplementation(DevToolsProvider.java:50)
	at org.openqa.selenium.devtools.DevToolsProvider.getImplementation(DevToolsProvider.java:29)
	at org.openqa.selenium.remote.Augmenter.augment(Augmenter.java:207)
	at org.openqa.selenium.remote.Augmenter.augment(Augmenter.java:178)
... 13 more
Caused by: java.net.http.WebSocketHandshakeException
	at java.net.http/jdk.internal.net.http.websocket.OpeningHandshake.resultFrom(OpeningHandshake.java:226)
	at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1150)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture.postFire(CompletableFuture.java:614)
	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:844)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: jdk.internal.net.http.websocket.CheckFailedException: Unexpected HTTP response status code 400
	at java.net.http/jdk.internal.net.http.websocket.OpeningHandshake.checkFailed(OpeningHandshake.java:343)
	at java.net.http/jdk.internal.net.http.websocket.OpeningHandshake.handleResponse(OpeningHandshake.java:252)
	at java.net.http/jdk.internal.net.http.websocket.OpeningHandshake.resultFrom(OpeningHandshake.java:222)
	... 10 more

Operating System

Windows 11, Ubuntu 22.04.5 LTS, MacOS 15.5

Docker Selenium version (image tag)

4.32.0-20250505

Selenium Grid chart version (chart version)

Copy link

@IlyaUk, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@VietND96
Copy link
Member

Can you also share a client script to reproduce?

@IlyaUk
Copy link
Author

IlyaUk commented Jun 2, 2025

Hi @VietND96
It seems like I need a little bit more time for testing the issue by myself. When I started to prepare a script to reproduce the problem in a new project with Selenium dependency only the problem has gone. So it seems like the issue might be connected with some other dependency I'm using in my project.

@amardeep2006
Copy link
Contributor

I will also suggest you to upgrade your test framework as well. It's a good practice to keep test framework updated to avoid any CDP compatibility issues.

@IlyaUk
Copy link
Author

IlyaUk commented Jun 6, 2025

Hi @VietND96,
I've tried several options to reproduce the problem in a new project with Selenium dependency only but with no effect.
However the issue with JDK initial request execution error is still reproducible on my production code that I can't share.
The exact configuration of a machine that executes tests: Selenium 4.32.0 (revision d17c8aa950), Ubuntu 22.04.5 LTS, JDK 17.0.14.
What I see in logs:

Chrome node:
10:46:26.364 INFO [LocalNode.newSession] - Session created by the Node. Id: df8955314a44f1345a62f66ce0b58cd7, Caps: Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 136.0.7103.59, chrome: {chromedriverVersion: 136.0.7103.49 (031848bc6ad0..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:41419}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:cdp: ws://localhost:4444/session..., se:cdpVersion: 136.0.7103.59, se:containerName: 2c81b6982de5, se:downloadsEnabled: true, se:gridWebSocketUrl: ws://localhost:3727/session..., se:noVncPort: 7900, se:vnc: ws://localhost:4444/session..., se:vncEnabled: true, se:vncLocalAddress: ws://172.18.0.3:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: accept, webSocketUrl: ws://localhost:4444/session..., webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true} 10:46:45.746 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:3727/session/df8955314a44f1345a62f66ce0b58cd7 10:46:45.845 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:41419/devtools/browser/a52f10f3-9ff2-4f44-9e9c-fa1f18ecc6ac 10:46:46.461 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:3727/session/df8955314a44f1345a62f66ce0b58cd7 10:46:46.480 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:41419/devtools/browser/a52f10f3-9ff2-4f44-9e9c-fa1f18ecc6ac 10:46:46.804 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:41419/devtools/browser/a52f10f3-9ff2-4f44-9e9c-fa1f18ecc6ac 10:46:46.821 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:3727/session/df8955314a44f1345a62f66ce0b58cd7 10:46:47.148 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:41419/devtools/browser/a52f10f3-9ff2-4f44-9e9c-fa1f18ecc6ac 10:46:47.161 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:3727/session/df8955314a44f1345a62f66ce0b58cd7 10:46:47.498 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:41419/devtools/browser/a52f10f3-9ff2-4f44-9e9c-fa1f18ecc6ac 10:46:47.511 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:3727/session/df8955314a44f1345a62f66ce0b58cd7 10:46:47.829 WARN [ProxyNodeWebsockets.apply] - Too many websocket connections initiated by df8955314a44f1345a62f66ce0b58cd7 10:46:48.073 WARN [ProxyNodeWebsockets.apply] - Too many websocket connections initiated by df8955314a44f1345a62f66ce0b58cd7
Selenium:
Caps: Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 136.0.7103.59, chrome: {chromedriverVersion: 136.0.7103.49 (031848bc6ad0..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:44571}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: {}, se:cdp: ws://localhost:4444/session..., se:cdpVersion: 136.0.7103.59, se:containerName: 20d4d8a1b2fc, se:downloadsEnabled: true, se:gridWebSocketUrl: ws://localhost:18642/sessio..., se:noVncPort: 7900, se:vnc: ws://localhost:4444/session..., se:vncEnabled: true, se:vncLocalAddress: ws://172.18.0.9:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: accept, webSocketUrl: ws://localhost:4444/session..., webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true} 10:46:47.831 WARN [ProxyWebsocketsIntoGrid.apply] - Connecting to upstream websocket failed org.openqa.selenium.remote.http.ConnectionFailedException: JdkWebSocket initial request execution error Build info: version: '4.32.0', revision: 'd17c8aa950' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.8.0-1024-aws', java.version: '21.0.6' Driver info: driver.version: unknown at org.openqa.selenium.remote.http.jdk.JdkHttpClient.openSocket(JdkHttpClient.java:253) at org.openqa.selenium.remote.tracing.TracedHttpClient.openSocket(TracedHttpClient.java:45) at org.openqa.selenium.grid.router.ProxyWebsocketsIntoGrid.apply(ProxyWebsocketsIntoGrid.java:73) at org.openqa.selenium.grid.router.ProxyWebsocketsIntoGrid.apply(ProxyWebsocketsIntoGrid.java:43) at org.openqa.selenium.netty.server.WebSocketUpgradeHandler.handleHttpRequest(WebSocketUpgradeHandler.java:137) at org.openqa.selenium.netty.server.WebSocketUpgradeHandler.channelRead(WebSocketUpgradeHandler.java:100) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler.onHttpRequestChannelRead(WebSocketServerExtensionHandler.java:158) at io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler.channelRead(WebSocketServerExtensionHandler.java:82) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at io.netty.handler.codec.http.HttpServerKeepAliveHandler.channelRead(HttpServerKeepAliveHandler.java:64) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1357) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:796) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:732) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:658) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:998) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:1583) Caused by: java.net.http.WebSocketHandshakeException at java.net.http/jdk.internal.net.http.websocket.OpeningHandshake.resultFrom(OpeningHandshake.java:224) at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1150) at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) at java.base/java.util.concurrent.CompletableFuture.postFire(CompletableFuture.java:614) at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:844) at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188) Caused by: jdk.internal.net.http.websocket.CheckFailedException: Unexpected HTTP response status code 400 at java.net.http/jdk.internal.net.http.websocket.OpeningHandshake.checkFailed(OpeningHandshake.java:341) at java.net.http/jdk.internal.net.http.websocket.OpeningHandshake.handleResponse(OpeningHandshake.java:250) at java.net.http/jdk.internal.net.http.websocket.OpeningHandshake.resultFrom(OpeningHandshake.java:220)

The issue doesn't reproduce with Selenium 4.25. Started from 4.26 it is present.
May I ask you for an advice please? Maybe something related to websockets or CDP has been changes significatly? Or maybe you have any ideas how to debug this issue by myself (add more logs etc...) to understand why the Selenium complains on JDKWebSocket?

@VietND96
Copy link
Member

VietND96 commented Jun 6, 2025

Too many websocket connections initiated by df8955314a44f1345a62f66ce0b58cd7 10:46:48.073 WARN [ProxyNodeWebsockets.apply] - Too many websocket connections initiated by df8955314a44f1345a62f66ce0b58cd7

I see this message, via Node container env var SE_OPTS, can you append this config also

--connection-limit-per-session 100

https://www.selenium.dev/documentation/grid/configuration/cli_options/#node

@IlyaUk
Copy link
Author

IlyaUk commented Jun 6, 2025

@VietND96, thanks a lot for the idea. It helped a bit:
--connection-limit-per-session {default 10} - 25 failed tests due to JDKWebSocket issue
--connection-limit-per-session 100 - 11 failed tests
--connection-limit-per-session 150 - still 1 failed test with the same problem.
What could have happened that I need to increase the default amount of connections by 15 times? No changes in test code or test infrastructure from our side. Just an attempt to upgrade Selenium. And failures occurred in tests that doesn't use CDP for files download/proxying directly. The exception mostly occured on click/input actions.

@VietND96
Copy link
Member

VietND96 commented Jun 6, 2025

Are you sharing the same session for multiple tests (e.g initialize session at 1st test and close session at 25th test, or open multiple tabs, or something else)? This would help to identify why lots of websockets are opened, since a huge number of ws are also causing Node to consume many resources or memory leaks.

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

Successfully merging a pull request may close this issue.

3 participants