selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🐛 Bug]: Hub hangs with "Unable to find session" after a while

Open xtianus opened this issue 4 years ago • 20 comments

What happened?

I've set up a Hub and 2 Nodes on three different Ubuntu servers. The Hub is on Ubuntu 16.04.7 LTS and the two nodes on Ubuntu 20.04.4 LTS. Selenium is driven by a Java program using standard libraries.

All works fine for a while (an hour or so), then suddenly the Hub stops responding. The symptoms are:

  • when connecting to http://myhub:4444/ui/index.html I get the normal "Selenium Grid" page but it is stuck on the "Loading..." message
  • the hub output shows many messages containing this:
"exception.message": "Unable to execute request for an existing session: Unable to find session with ID: 98d1a9efa8b787398b29c2d6c5f2ddab
Build info: version: '4.1.2', revision: '9a5a329c5a'
System info: host: 'controller', ip: 'xx.xx.xx.xx', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-210-generic', java.version: '1.8.0_292'
Driver info: driver.version: unknown"
  • the java program gets the exception shown in the "Relevant log output" box.

If I restart the Hub, all goes back to normal: I don't have to restart either the nodes or the Java program.

Command to start the hub:

java -jar selenium-server-4.1.2.jar hub --config hub.toml

Content of hub.toml:

[server]
port = 4444
registration-secret = "xxxxxx"
[sessionqueue]
session-request-timeout = 300

Command to start the node:

java -jar selenium-server-4.1.2.jar node --config node.toml

Content of node.toml:

[server]
port = 5555
registration-secret = "xxxxxx"
[node]
hub = "xx.xx.xx.xx"
override-max-sessions = true
max-sessions = 8
session-timeout = 60
detect-drivers = false
[[node.driver-configuration]]
display-name = "Chrome Latest"
stereotype = "{\"browserName\": \"chrome\"}"
webdriver-executable = '/mypath/chromedriver'

Output of top (last line is the hub):

top - 15:11:10 up 22:00,  3 users,  load average: 0.20, 0.23, 0.19
Tasks: 208 total,   1 running, 207 sleeping,   0 stopped,   0 zombie
%Cpu(s): 12.5 us,  1.2 sy,  0.0 ni, 82.3 id,  0.2 wa,  0.0 hi,  1.7 si,  2.2 st
KiB Mem :  8175040 total,  1773696 free,  3951596 used,  2449748 buff/cache
KiB Swap:  8388604 total,  8348196 free,    40408 used.  3875604 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  908 tomcat8   20   0 4055844 1.196g  17808 S  21.9 15.3 115:44.34 java
 1183 mysql     20   0 1670676 528960  15472 S   2.3  6.5  25:39.78 mysqld
15065 root      20   0 4685516 346108  19128 S   2.0  4.2  11:59.94 java

If I restart just the hub, all goes back to normal: nodes register and I see the queue growing in the Selenium Grid web console.

How can we reproduce the issue?

I know you need to reproduce the problem but I can't share my whole application: it's not just a script and it needs a lot of work to be set up (tomcat, mysql, user data etc.)

Relevant log output

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '4.1.2', revision: '9a5a329c5a'
System info: host: 'controller', ip: 'xx.xx.xx.xx', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-210-generic', java.version: '1.8.0_292'
Driver info: net.yadaframework.selenium.YadaSeleniumUtil$1
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [user-data-dir=/srv/xxx/..., user-agent=Mozilla/5.0 (Win...], extensions: []}, proxy: {httpProxy: yy.yy.yy.yy:9092, proxyType: manual, sslProxy: yy.yy.yy.yy:9092}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [user-data-dir=/srv/xxx/..., user-agent=Mozilla/5.0 (Win...], extensions: []}, proxy: Proxy(manual, http=yy.yy.yy...}}]
Capabilities {}
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:576)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:245)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:161)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:143)
        at net...
        at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:131)
        at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:74)
        at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:82)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.UncheckedIOException: java.io.IOException: Stream closed
        at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:80)
        at org.openqa.selenium.remote.http.RetryRequest.lambda$apply$6(RetryRequest.java:80)
        at net.jodah.failsafe.Functions.lambda$get$0(Functions.java:48)
        at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
        at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
        at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
        at net.jodah.failsafe.Execution.executeSync(Execution.java:128)
        at net.jodah.failsafe.FailsafeExecutor.call(FailsafeExecutor.java:379)
        at net.jodah.failsafe.FailsafeExecutor.get(FailsafeExecutor.java:68)
        at org.openqa.selenium.remote.http.RetryRequest.lambda$apply$7(RetryRequest.java:80)
        at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
        at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
        at org.openqa.selenium.remote.http.netty.NettyHttpHandler.execute(NettyHttpHandler.java:51)
        at org.openqa.selenium.remote.http.RetryRequest.lambda$apply$6(RetryRequest.java:80)
        at net.jodah.failsafe.Functions.lambda$get$0(Functions.java:48)
        at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
        at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
        at net.jodah.failsafe.RetryPolicyExecutor.lambda$supply$0(RetryPolicyExecutor.java:66)
        at net.jodah.failsafe.Execution.executeSync(Execution.java:128)
        at net.jodah.failsafe.FailsafeExecutor.call(FailsafeExecutor.java:379)
        at net.jodah.failsafe.FailsafeExecutor.get(FailsafeExecutor.java:68)
        at org.openqa.selenium.remote.http.RetryRequest.lambda$apply$7(RetryRequest.java:80)
        at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
        at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
        at org.openqa.selenium.remote.http.netty.NettyClient.execute(NettyClient.java:110)
        at org.openqa.selenium.remote.tracing.TracedHttpClient.execute(TracedHttpClient.java:55)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:84)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:62)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
        at org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:51)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:558)
        ... 17 common frames omitted
Caused by: java.io.IOException: Stream closed
        at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:159)
        at java.io.BufferedInputStream.available(BufferedInputStream.java:410)
        at java.io.FilterInputStream.available(FilterInputStream.java:168)
        at java.io.PushbackInputStream.available(PushbackInputStream.java:277)
        at io.netty.handler.stream.ChunkedStream.isEndOfInput(ChunkedStream.java:82)
        at io.netty.handler.stream.ChunkedStream.readChunk(ChunkedStream.java:109)
        at io.netty.handler.stream.ChunkedStream.readChunk(ChunkedStream.java:36)
        at io.netty.handler.stream.ChunkedWriteHandler.doFlush(ChunkedWriteHandler.java:229)
        at io.netty.handler.stream.ChunkedWriteHandler.flush(ChunkedWriteHandler.java:131)
        at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:750)
        at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:765)
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:790)
        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:758)
        at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1020)
        at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:311)
        at org.asynchttpclient.netty.request.body.NettyInputStreamBody.write(NettyInputStreamBody.java:77)
        at org.asynchttpclient.netty.request.NettyRequestSender.writeRequest(NettyRequestSender.java:433)
        at org.asynchttpclient.netty.channel.NettyConnectListener.writeRequest(NettyConnectListener.java:80)
        at org.asynchttpclient.netty.channel.NettyConnectListener.onSuccess(NettyConnectListener.java:156)
        at org.asynchttpclient.netty.channel.NettyChannelConnector$1.onSuccess(NettyChannelConnector.java:92)
        at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:26)
        at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:20)
        at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
        at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
        at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
        at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
        at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
        at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:605)
        at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)
        at io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84)
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:300)
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:335)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:710)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        ... 1 common frames omitted

Operating System

Ubuntu 16.04.7 LTS

Selenium version

Java 1.8.0_292, Selenium 4.1.2.

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

Chrome 98.0.4758.102

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

ChromeDriver 98.0.4758.80

Are you using Selenium Grid?

4.1.2

xtianus avatar Feb 28 '22 14:02 xtianus

@xtianus, 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, 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!

github-actions[bot] avatar Feb 28 '22 14:02 github-actions[bot]

Update

I left the system run overnight and currently it is in a broken state, but different from before:

  • the web console at http://myhost:4444/ui/index.html responds and correctly shows two active nodes. One of them is shown with 1 session (permanently), the other one with 0 sessions. The queue is empty showing "There are no running or queued sessions at the moment" (I think I should see at least one session there, right?).

image image

  • if I connect to my nodes with VNC I see >50 "new tab" chrome instances and >10 "This page isn't working" chrome pages, each.

image

  • when I run the client java program the Hub logs the following line and nodes are not called at all:
10:32:38.586 WARN [SeleniumSpanExporter$1.lambda$export$0] - {"traceId": "92877572bc7c9690c97264e7c9292c6b","eventTime": 1646127158585632434,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue","http.host": "xxx.xxx.xxx.xxx:4444","http.method": "POST","http.request_content_length": "1105","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession","http.user_agent": "selenium\u002f4.1.2 (java unix)"}}
  • the java program gets the usual exception:
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
  • I restarted just the hub and the java program managed to start one new session and no more
  • I restarted both the nodes and the hub (not the java program) and all went back to normal

xtianus avatar Mar 01 '22 09:03 xtianus

Ok, not sure how to proceed because I cannot figure out what the exact problem is with just the stacktrace.

I do not need your exact same application, but at least something that helps me to reproduce it.

diemol avatar Mar 02 '22 16:03 diemol

@diemol maybe there's some log I can enable to better understand what's happening? Maybe a heap/thread dump of the Hub when stuck?

xtianus avatar Mar 02 '22 17:03 xtianus

I could have a look at the full hub and nodes logs and see if I can understand what is happening. Maybe you can share them in gists?

diemol avatar Mar 04 '22 16:03 diemol

I have set up a cron job that queries the hub queue with

curl -m 4 -X POST -H "Content-Type: application/json" --data '{"query":"{ grid { sessionQueueSize } }"}' -s http://localhost:4444/graphql

When the hub gets stuck, the curl command exits with status 28. In such case the script sends me an email so I can manually check what's going on. So I've made some thread dumps while the hub was stuck using

jcmd $pid Thread.print

I do one dump ("before"), then I run curl again and while it's waiting I do another dump ("while"). This is what I found.

Dump 1: 1646414398 https://gist.github.com/xtianus/de9953947cdd353a06bb6e8ecc3e25c6 The "before" dump and the "while" dump differ in thread-21 that was TIMED_WAITING at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:66) before the curl call and is TIMED_WAITING at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460) while curl is running and stuck.

Dump 2: 1646415358 https://gist.github.com/xtianus/774f47d5c6c2e92bae4cca50c53698ec This is taken 15 minutes later without restarting the hub. The two dumps differ on pool-2-thread-43 that was at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460) before and at org.openqa.selenium.remote.http.Contents$MemoizedSupplier.get(Contents.java:158) while.

Two further dumps are similar.

I was hoping to get some hindsight but I didn't.

I will check the logs next.

xtianus avatar Mar 04 '22 18:03 xtianus

I tried to start with OpenTelemetry but I run into an issue: https://github.com/SeleniumHQ/selenium/issues/10416

xtianus avatar Mar 07 '22 10:03 xtianus

So I enabled trace on the hub and the nodes using these options in hub.toml and node.toml:

[logging]
http-logs = true
log-file = '/mypath/log/trace.log'
log-level = "FINE"

In any case, I restarted everyting at around 13:03 CET in order to get clean logs.

EDIT: I made a mistake and I didn't restart the hub after changing the config so it does not log at DEBUG level.

What I didn't realise was that the nodes are in the UTC timezone so you need to add 1h from the nodes log in order to match it with the hub. I replaced sensitive information with garbled data. For example n2.ip.xx.xx is the ip address of node2. The nodes are called "n2" and "n3". The hub is called "hub". Please let me know if I left anything sensitive in the clear.

I'm attaching the logs to this post because they are too big for gist.

hub-trace-1646657105.zip

n2-trace-1646657109.zip

n3-trace-1646657115.zip

The hub log starts at 12:50:57 CET, which is 11:50:57 UTC The n2/n3 log start at 12:03 UTC which is 13:03 CET, so 13 minutes later. I think I restarted the nodes after the hub startup. You can see the nodes registering at the correct time in the hub trace.

So from the hub logs you will see that I get a lot of NoSuchSessionException but all keeps working until, at 13:45 CET, my cron job finds that the hub is stuck and rotates the trace logs.

The nodes are complaining because I'm using 8 sessions on a 4-processor (virtual) server. I need to do so in order to optimize server usage because there is a lot of waiting during tests. Next thing I'll do is not overriding the max session parameter.

xtianus avatar Mar 07 '22 14:03 xtianus

I removed the max session override but nothing changed: last night selenium hub hanged 6 times.

I collected the traces and the thread dump before restarting it. The thread dump of the hub is attached here:

hub-threads-1646724961.zip

All threads seem to be waiting for something. Many are in Contents$MemoizedSupplier.get() as if they are waiting for some network activity. I should mention that the hub and the nodes are in different countries. In the trace that started at 07:56:15 and ended at 08:36:01 I only had 12 TimeoutException (after 180000 ms) though.

It's quite hard to follow the trace because there's no thread ID on the line (just the method) and I can't tell where a thread is going. I just configured structured-logs = true so maybe I'll get better logs next time. I also increased max-threads to a much bigger value: 24 instead of the default of 6.

xtianus avatar Mar 08 '22 09:03 xtianus

With structured-logs = true I collected unreadable logs that don't offer any useful additional information. I wanted to trace the graphql call that I use to detect the hang but there is no thread id in the log:

{"class": "RequestConverter",
	"log-level": "DEBUG",
	"log-message": "Start of http request: DefaultHttpRequest(decodeResult: success,
	 version: HTTP/1.1)
POST /graphql HTTP/1.1
Host: localhost:4444
User-Agent: curl-7.47.0
Accept: *-*
Content-Type: application-json
content-length: 41",
	"log-name": "org.openqa.selenium.netty.server.RequestConverter",
	"log-time-local": "2022-03-08T22:40:01.961+01:00",
	"log-time-utc": "2022-03-08T21:40:01.961Z",
	"method": "channelRead0"}

I'm about to give up on Selenium Grid. Maybe I'll try relocating the servers to the same local network and see if anything changes. Maybe.

xtianus avatar Mar 08 '22 22:03 xtianus

We have similar issues. I could track it down to the grid nodes. It looks like after doing some work and the in the idle phase, internal messages are sent regularly, which either are empty or already consumed. This leads to this stack-trace:

Name: pool-3-thread-64 State: TIMED_WAITING on java.io.PipedInputStream@5772c3f2 Total blocked: 0 Total waited: 60

Stack trace: [email protected]/java.lang.Object.wait(Native Method) [email protected]/java.io.PipedInputStream.read(PipedInputStream.java:326) [email protected]/java.io.PipedInputStream.read(PipedInputStream.java:377) [email protected]/java.io.InputStream.read(InputStream.java:218) app//com.google.common.io.ByteStreams.copy(ByteStreams.java:112) app//org.openqa.selenium.remote.http.Contents$MemoizedSupplier.get(Contents.java:158) locked org.openqa.selenium.remote.http.Contents$MemoizedSupplier@334449ae app//org.openqa.selenium.remote.http.Contents$MemoizedSupplier.get(Contents.java:141) app//org.openqa.selenium.remote.http.Contents.bytes(Contents.java:75) app//org.openqa.selenium.remote.http.Contents.string(Contents.java:92) app//org.openqa.selenium.remote.http.Contents.string(Contents.java:96) app//org.openqa.selenium.grid.node.CustomLocatorHandler.execute(CustomLocatorHandler.java:110) app//org.openqa.selenium.remote.http.Route$CombinedRoute.handle(Route.java:336) app//org.openqa.selenium.remote.http.Route.execute(Route.java:68) app//org.openqa.selenium.grid.node.Node.execute(Node.java:240) app//org.openqa.selenium.remote.http.Route$CombinedRoute.handle(Route.java:336) app//org.openqa.selenium.remote.http.Route.execute(Route.java:68) app//org.openqa.selenium.remote.AddWebDriverSpecHeaders.lambda$apply$0(AddWebDriverSpecHeaders.java:35) app//org.openqa.selenium.remote.AddWebDriverSpecHeaders$$Lambda$434/0x0000000800e1e298.execute(Unknown Source) app//org.openqa.selenium.remote.ErrorFilter.lambda$apply$0(ErrorFilter.java:44) app//org.openqa.selenium.remote.ErrorFilter$$Lambda$433/0x0000000800e1e068.execute(Unknown Source) app//org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:64) app//org.openqa.selenium.remote.ErrorFilter.lambda$apply$0(ErrorFilter.java:44) app//org.openqa.selenium.remote.ErrorFilter$$Lambda$433/0x0000000800e1e068.execute(Unknown Source) app//org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:64) app//org.openqa.selenium.netty.server.SeleniumHandler.lambda$channelRead0$0(SeleniumHandler.java:44) app//org.openqa.selenium.netty.server.SeleniumHandler$$Lambda$430/0x0000000800e1da08.run(Unknown Source) [email protected]/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) [email protected]/java.util.concurrent.FutureTask.run(FutureTask.java:264) [email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [email protected]/java.lang.Thread.run(Thread.java:833)

From the screenshot, you can see there are many thready named 'pool-3-thread-XX'. We have set our sessionTimeout to 180 seconds, which matches the interval a thread is added.

selenium-grid-node-thread-leak

selenium-grid-node-thread-leak2

Eventually, the grid node has to many handles open and blocks/hangs. Restarting the node solves the issue temporarly.

We're using Selenium Grid 4.1.2 on a Windows 10 system

itarob avatar Mar 14 '22 13:03 itarob

I upgraded my grid to 4 and now have a similar issue. After about an hour of running tests, I'll start getting "Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure." when trying to get a new chrome instance. When this happens, I notice that the hub api stops responding to my requests when I call the graphql endpoint to get status details. 4.1.3 did not fix the issue for me.

enivid avatar Mar 30 '22 18:03 enivid

I upgraded my grid to 4 and now have a similar issue. After about an hour of running tests, I'll start getting "Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure." when trying to get a new chrome instance. When this happens, I notice that the hub api stops responding to my requests when I call the graphql endpoint to get status details. 4.1.3 did not fix the issue for me.

I figured out that the problem is letting the nodes clean up old browser sessions that have hit their timeout limit. I have some very long running tests and those tests were not closing their browser sessions and allowing the grid to just shut them down. After I fixed all the tests, the problem went away and the grid stays alive and happy.

enivid avatar Mar 31 '22 17:03 enivid

@enivid did you get any log either in the nodes or the hub that told you about the cleanup? That would help me detect if this happens to me too.

xtianus avatar Mar 31 '22 18:03 xtianus

Thanks for sharing the detailed logs, @xtianus. With that, I was able to understand why this bug happens.

So, here is the sequence of events triggering the bug:

  • Session starts normally
  • A bunch of commands are triggered withing your tests (interacting a lot with /timeouts and /elements)
  • At some point, one of the commands gets stuck and it gets a timeout. The default timeout value is 180s.
  • You have configured a session-timeout of 60s. So, while the command is still being executed, the session-timeout kicks in, and the session is removed from the Grid.
  • However, since the command request is still running, it is not possible to clean up the session (so, to close the browser).
  • When the command timeout happens, you get a timeout response in the test, and in version 4.1.2 we still had retries enabled by default, which is why the command is retried and then you see lots of Unable to find session with ID.
  • Eventually, lots of browsers stay open and the Grid runs out of resources, and this will likely affect GraphQL, because it is getting all the status information from the Nodes.

Most of the people do not see this because they use the default session-timeout of 300s.

Nevertheless, this is a bug in the Grid because the command timeout should not be hard coded to 180s, but rather be tied to the Node's configured session-timeout. I am working on a fix for this that will be available either in 4.1.4 or 4.2.0, whatever comes first.

In the meantime, if you set the session-timeout to 300s (default), you should stop seeing this errors. Also, upgrading to 4.1.3 should give you cleaner logs to debug further issues because retries are not enabled by default everywhere.

diemol avatar Apr 01 '22 13:04 diemol

Here is a jar I generated with this fix, you can try it while the release is done.

selenium-server-4.1.3-df41b58162.zip

diemol avatar Apr 01 '22 14:04 diemol

@diemol I just replaced the selenium jar with your patched version without changing anything else (not even the 60s timeout). All looks fine for now. I'll let you know if I still run into problems or not.

xtianus avatar Apr 01 '22 16:04 xtianus

@diemol the Hub has been working so far. The patch fixed the problem.

xtianus avatar Apr 05 '22 19:04 xtianus

Thanks for the feedback, @xtianus! We expect to do a new release next week.

diemol avatar Apr 07 '22 15:04 diemol

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar May 08 '22 00:05 github-actions[bot]