Skip to content

[๐Ÿ› Bug]: OpenQA.Selenium.WebDriverException : Unexpected error creating WebSocket DevTools session.ย #14714

@MJB222398

Description

@MJB222398

What happened?

Jenkins running a 35 minutes worth of tests on Chrome, Edge, and Firefox in parallel using Docker selenium grid. Chrome and Edge tests all passed but 6/7 minutes in I had a Firefox one fail with the below exception. After this one failed test subsequent tests on Firefox were all fine. Tests runs following this were all fine and no code or environmental changes were made before or after this failure so the issue is intermittent.

OpenQA.Selenium.WebDriverException : Unexpected error creating WebSocket DevTools session.
----> System.TimeoutException : Could not connect to browser within 30 seconds
at OpenQA.Selenium.Remote.RemoteWebDriver.GetDevToolsSession(DevToolsOptions options)
at OpenQA.Selenium.Remote.RemoteWebDriver.GetDevToolsSession()
at OpenQA.Selenium.JavaScriptEngine.<>c__DisplayClass8_0.<.ctor>b__0()
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at OpenQA.Selenium.JavaScriptEngine.StartEventMonitoring()
--TimeoutException
at OpenQA.Selenium.DevTools.WebSocketConnection.Start(String url)
at OpenQA.Selenium.DevTools.DevToolsSession.InitializeSocketConnection()
at OpenQA.Selenium.DevTools.DevToolsSession.StartSession()
at OpenQA.Selenium.Remote.RemoteWebDriver.<>c__DisplayClass29_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at OpenQA.Selenium.Remote.RemoteWebDriver.GetDevToolsSession(DevToolsOptions options)

How can we reproduce the issue?

var driverOptions = new FirefoxOptions() { EnableDevToolsProtocol = true };
driverOptions.AddArguments("-profile", "home/seluser/.mozilla/firefox/seluser_profile");

var seleniumRemoteWebDriver = new RemoteWebDriver(
        remoteAddress: new Uri(_driverConfiguration.Url),
        capabilities: driverOptions.ToCapabilities(),
        commandTimeout: TimeSpan.FromSeconds(_driverConfiguration.CommandTimeout));
seleniumRemoteWebDriver.Manage().Window.Maximize();

var jsEngine = new JavaScriptEngine(seleniumRemoteWebDriver)

jsEngine.JavaScriptConsoleApiCalled += (_, e) => { lock (_consoleLogsLock) { _consoleLogs.Add(e); } };
await jsEngine.StartEventMonitoring();

Relevant log output

16:49:09.528 INFO [LocalNode.newSession] - Session created by the Node. Id: 2b75b239-f11e-402a-b8a4-1f80fa901383, Caps: Capabilities {acceptInsecureCerts: false, browserName: firefox, browserVersion: 128.0.3, moz:accessibilityChecks: false, moz:buildID: 20240725162350, moz:debuggerAddress: 127.0.0.1:15564, moz:firefoxOptions: {args: [-profile, home/seluser/.mozilla/firef...], prefs: {remote.active-protocols: 3}}, moz:geckodriverVersion: 0.34.0, moz:headless: false, moz:platformVersion: 5.4.0-189-generic, moz:processID: 8045, moz:profile: /home/seluser/.mozilla/fire..., moz:shutdownTimeout: 60000, moz:webdriverClick: true, moz:windowless: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://localhost:4444/session..., se:cdpVersion: 85.0, se:containerName: , se:noVncPort: 7900, se:vnc: ws://localhost:4444/session..., se:vncEnabled: true, se:vncLocalAddress: ws://192.168.32.7:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, userAgent: Mozilla/5.0 (X11; Linux x86...}
16:49:09.549 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://127.0.0.1:15564/devtools/browser/fbcc0353-f46e-4150-a50f-0ea5bd924b23
16:49:15.601 INFO [SessionSlot.stop] - Stopping session 2b75b239-f11e-402a-b8a4-1f80fa901383
16:49:17.232 INFO [LocalNode.newSession] - Session created by the Node. Id: 62a74535-935b-4865-9940-1a4c1f79bce5, Caps: Capabilities {acceptInsecureCerts: false, browserName: firefox, browserVersion: 128.0.3, moz:accessibilityChecks: false, moz:buildID: 20240725162350, moz:debuggerAddress: 127.0.0.1:28252, moz:firefoxOptions: {args: [-profile, home/seluser/.mozilla/firef...], prefs: {remote.active-protocols: 3}}, moz:geckodriverVersion: 0.34.0, moz:headless: false, moz:platformVersion: 5.4.0-189-generic, moz:processID: 8435, moz:profile: /home/seluser/.mozilla/fire..., moz:shutdownTimeout: 60000, moz:webdriverClick: true, moz:windowless: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://localhost:4444/session..., se:cdpVersion: 85.0, se:containerName: , se:noVncPort: 7900, se:vnc: ws://localhost:4444/session..., se:vncEnabled: true, se:vncLocalAddress: ws://192.168.32.7:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, userAgent: Mozilla/5.0 (X11; Linux x86...}
16:49:17.249 WARN [DefaultChannelPipeline.onUnhandledInboundException] - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.remote.http.HttpRequest.setContent(org.openqa.selenium.remote.http.Contents$Supplier)" because "this.request" is null
	at org.openqa.selenium.netty.server.RequestConverter.channelRead0(RequestConverter.java:146)
	at org.openqa.selenium.netty.server.RequestConverter.channelRead0(RequestConverter.java:53)
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
	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.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:102)
	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.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:102)
	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 org.openqa.selenium.netty.server.WebSocketUpgradeHandler.channelRead(WebSocketUpgradeHandler.java:98)
	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.channelRead(WebSocketServerExtensionHandler.java:90)
	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:1407)
	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:918)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994)
	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:840)

The above repeated many times, and then the below repeated many times

16:49:31.011 WARN [DefaultChannelPipeline.onUnhandledInboundException] - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.lang.NullPointerException

The driver logs didn't contain anything about this:

2024-11-04 16:49:16.297 DEBUG HttpCommandExecutor: Executing command: []: newSession {"capabilities":{"firstMatch":[{"browserName":"firefox","moz:firefoxOptions":{"args":["-profile","home/seluser/.mozilla/firefox/seluser_profile"],"prefs":{"remote.active-protocols":3}},"moz:debuggerAddress":true}]}}
2024-11-04 16:49:16.297 TRACE HttpCommandExecutor: >> Method: POST, RequestUri: 'http://localhost:4444/wd/hub/session', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers:
{
  Accept: application/json; charset=utf-8
  User-Agent: selenium/4.23.0
  User-Agent: (.net linux)
  Content-Type: application/json; charset=utf-8
  Content-Length: 215
}
{"capabilities":{"firstMatch":[{"browserName":"firefox","moz:firefoxOptions":{"args":["-profile","home/seluser/.mozilla/firefox/seluser_profile"],"prefs":{"remote.active-protocols":3}},"moz:debuggerAddress":true}]}}
2024-11-04 16:49:17.238 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Cache-Control: no-cache
  Content-Length: 1803
  Content-Type: application/json; charset=utf-8
}
2024-11-04 16:49:17.238 DEBUG HttpCommandExecutor: Response: (62a74535-935b-4865-9940-1a4c1f79bce5 Success: System.Collections.Generic.Dictionary`2[System.String,System.Object])
2024-11-04 16:49:17.238 DEBUG HttpCommandExecutor: Executing command: [62a74535-935b-4865-9940-1a4c1f79bce5]: maximizeWindow {}
2024-11-04 16:49:17.238 TRACE HttpCommandExecutor: >> Method: POST, RequestUri: 'http://localhost:4444/wd/hub/session/62a74535-935b-4865-9940-1a4c1f79bce5/window/maximize', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers:
{
  Accept: application/json; charset=utf-8
  User-Agent: selenium/4.23.0
  User-Agent: (.net linux)
  Content-Type: application/json; charset=utf-8
  Content-Length: 2
}
{}
2024-11-04 16:49:17.241 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Cache-Control: no-cache
  Content-Length: 50
  Content-Type: application/json; charset=utf-8
}
2024-11-04 16:49:17.241 DEBUG HttpCommandExecutor: Response: ( Success: System.Collections.Generic.Dictionary`2[System.String,System.Object])

Operating System

Ubuntu

Selenium version

4.23.0

What are the browser(s) and version(s) where you see this issue?

Firefox 128.0

What are the browser driver(s) and version(s) where you see this issue?

moz:geckodriverVersion: 0.34.0

Are you using Selenium Grid?

4.23.0-20240727

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-dotnet.NET BindingsI-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions