selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[πŸ› Bug]: Selenium grid 4.49.0 - idle sessions are not remove after session timeout and unable to delete sessions

Open vicozohili opened this issue 2 months ago β€’ 28 comments

Description

I start the selenium grid on a linux server using below commands:

nohup java -Dwebdriver.http.factory=jdk-http-client -jar selenium-server-4.49.0.jar hub &

nohup java -Dwebdriver.http.factory=jdk-http-client -Dwebdriver.chrome.driver=./chromedriver -Dwebdriver.chrome.whitelistedIps= -jar selenium-server-4.49.0.jar node --selenium-manager true --override-max-sessions true --max-sessions 20 --session-timeout 72000 --delete-session-on-ui true &

If a session is still active after 20 hours, it used to be automatically removed as per the configuration above. In Selenium Grid 4.48.0 and 4.49.0, this functionality is broken. Sessions remain active indefinitely.

I have tried deleting the sessions with: curl --request DELETE "http://localhost:5555/se/grid/node/session/" --header "X-REGISTRATION-SECRET;"

but still not able to do so and I get the error { "value": { "error": "invalid session id", "stacktrace": "org.openqa.selenium.NoSuchSessionException: Cannot find session with id: 721500a671676dcf1e489c30f24eeb63\nBuild info: version: '4.49.0', revision: 'bedb24f bedb24f6f703876e7e4c5d506f0d697eb358c720'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '4.18.0-553.84.1.el8_10.x86_64', java.version: '17.0.17'\nDriver info: driver.version: unknown\n\tat org.openqa.selenium.grid.node.local.LocalNode.stop(LocalNode.java:1178)\n\tat org.openqa.selenium.grid.node.StopNodeSession.execute(StopNodeSession.java:38)\n\tat org.openqa.selenium.remote.http.Route$TemplatizedRoute.handle(Route.java:192)\n\tat org.openqa.selenium.remote.http.Route.execute(Route.java:69)\n\tat org.openqa.selenium.grid.security.RequiresSecretFilter.lambda$apply$0(RequiresSecretFilter.java:61)\n\tat org.openqa.selenium.remote.tracing.SpanWrappedHttpHandler.execute(SpanWrappedHttpHandler.java:87)\n\tat org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:63)\n\tat org.openqa.selenium.remote.http.Route$CombinedRoute.handle(Route.java:358)\n\tat org.openqa.selenium.remote.http.Route.execute(Route.java:69)\n\tat org.openqa.selenium.grid.node.Node.execute(Node.java:316)\n\tat org.openqa.selenium.remote.http.Route$CombinedRoute.handle(Route.java:358)\n\tat org.openqa.selenium.remote.http.Route.execute(Route.java:69)\n\tat org.openqa.selenium.remote.AddWebDriverSpecHeaders.lambda$apply$0(AddWebDriverSpecHeaders.java:35)\n\tat org.openqa.selenium.remote.ErrorFilter.lambda$apply$0(ErrorFilter.java:44)\n\tat org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:63)\n\tat org.openqa.selenium.remote.ErrorFilter.lambda$apply$0(ErrorFilter.java:44)\n\tat org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:63)\n\tat org.openqa.selenium.netty.server.SeleniumHandler.lambda$channelRead0$0(SeleniumHandler.java:49)\n\tat java.base\u002fjava.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)\n\tat java.base\u002fjava.util.concurrent.FutureTask.run(FutureTask.java:264)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)\n\tat java.base\u002fjava.lang.Thread.run(Thread.java:840)\n", "message": "Cannot find session with id: 721500a671676dcf1e489c30f24eeb63\nBuild info: version: '4.49.0', revision: 'bedb24f bedb24f6f703876e7e4c5d506f0d697eb358c720'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '4.18.0-553.84.1.el8_10.x86_64', java.version: '17.0.17'\nDriver info: driver.version: unknown"

Reproducible Code

--session-timeout config in CLI does not work

and

curl --request DELETE "http://localhost:5555/se/grid/node/session/<session-id>" --header "X-REGISTRATION-SECRET;"

results in below error:

{
  "value": {
    "error": "invalid session id",
    "stacktrace": "org.openqa.selenium.NoSuchSessionException: Cannot find session with id: 721500a671676dcf1e489c30f24eeb63\nBuild info: version: '4.49.0', revision: 'bedb24f bedb24f6f703876e7e4c5d506f0d697eb358c720'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '4.18.0-553.84.1.el8_10.x86_64', java.version: '17.0.17'\nDriver info: driver.version: unknown\n\tat org.openqa.selenium.grid.node.local.LocalNode.stop(LocalNode.java:1178)\n\tat org.openqa.selenium.grid.node.StopNodeSession.execute(StopNodeSession.java:38)\n\tat org.openqa.selenium.remote.http.Route$TemplatizedRoute.handle(Route.java:192)\n\tat org.openqa.selenium.remote.http.Route.execute(Route.java:69)\n\tat org.openqa.selenium.grid.security.RequiresSecretFilter.lambda$apply$0(RequiresSecretFilter.java:61)\n\tat org.openqa.selenium.remote.tracing.SpanWrappedHttpHandler.execute(SpanWrappedHttpHandler.java:87)\n\tat org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:63)\n\tat org.openqa.selenium.remote.http.Route$CombinedRoute.handle(Route.java:358)\n\tat org.openqa.selenium.remote.http.Route.execute(Route.java:69)\n\tat org.openqa.selenium.grid.node.Node.execute(Node.java:316)\n\tat org.openqa.selenium.remote.http.Route$CombinedRoute.handle(Route.java:358)\n\tat org.openqa.selenium.remote.http.Route.execute(Route.java:69)\n\tat org.openqa.selenium.remote.AddWebDriverSpecHeaders.lambda$apply$0(AddWebDriverSpecHeaders.java:35)\n\tat org.openqa.selenium.remote.ErrorFilter.lambda$apply$0(ErrorFilter.java:44)\n\tat org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:63)\n\tat org.openqa.selenium.remote.ErrorFilter.lambda$apply$0(ErrorFilter.java:44)\n\tat org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:63)\n\tat org.openqa.selenium.netty.server.SeleniumHandler.lambda$channelRead0$0(SeleniumHandler.java:49)\n\tat java.base\u002fjava.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)\n\tat java.base\u002fjava.util.concurrent.FutureTask.run(FutureTask.java:264)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)\n\tat java.base\u002fjava.lang.Thread.run(Thread.java:840)\n",
    "message": "Cannot find session with id: 721500a671676dcf1e489c30f24eeb63\nBuild info: version: '4.49.0', revision: 'bedb24f bedb24f6f703876e7e4c5d506f0d697eb358c720'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '4.18.0-553.84.1.el8_10.x86_64', java.version: '17.0.17'\nDriver info: driver.version: unknown"

ℹ️ Last known working version: 4.44.0

vicozohili avatar Sep 21 '26 10:09 vicozohili

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

Selenium Triage Team: remember to follow the Triage Guide

selenium-ci avatar Sep 21 '26 10:09 selenium-ci

@vicozohili a couple of things that would help narrow this down:

  1. Does the node log show "Session id timed out, stopping..." once the timeout has passed? If it does, the node is expiring the session and the problem is further along, in the hub handling the close. If it doesn't, the node isn't expiring it at all.

  2. Could you try 4.45.0, 4.46.0 and 4.47.0? You've got 4.44.0 as last known working and 4.48.0 as broken, so knowing which release introduced it would narrow the change down a lot. A short --session-timeout (say 60) should make each check quick rather than waiting 20 hours.

Also, the first curl has no session id in the path, and both send an empty X-REGISTRATION-SECRET header, so that DELETE may be failing for a separate reason. The NoSuchSessionException on the second one is the more interesting part - it suggests the node no longer knows about a session the Grid still shows as active.

I'm happy to work on this - once we know which release introduced it, I can reproduce it with a hub and node locally and narrow it down to the commit.

yashp676 avatar Sep 21 '26 12:09 yashp676

@yashp676 , unfortunately I cannot rollback anytime soon. For now I have to restart the grid daily to clear out stale sessions. However, this is what I can see in the logs today.

20:42:28.685 INFO [LocalNode.newSession] - Session created by the Node. Id: 721500a671676dcf1e489c30f24eeb63, Caps: {acceptInsecureCerts=true, browserName=chrome, browserVersion=153.0.8010.52, chrome={chromedriverVersion=153.0.8010.52 (78e5e45d4bb41035e17ea4da2cc257f496416ac9-refs/branch-heads/8010@{#1443}), userDataDir=/tmp/org.chromium.Chromium.scoped_dir.prMD9q}, fedcm:accounts=true, goog:chromeOptions={debuggerAddress=localhost:34273}, goog:loggingPrefs={browser=SEVERE, driver=SEVERE, performance=SEVERE}, goog:processID=2416365, networkConnectionEnabled=false, pageLoadStrategy=normal, platformName=linux, proxy=Proxy(), se:bidiEnabled=false, se:cdp=ws://<hostname/ip>:4444/session/721500a671676dcf1e489c30f24eeb63/se/cdp, se:cdpVersion=153.0.8010.52, se:deleteSessionOnUi=true, setWindowRect=true, strictFileInteractability=false, timeouts={implicit=0, pageLoad=300000, script=30000}, unhandledPromptBehavior=dismiss and notify, webauthn:extension:cmtgKey=true, webauthn:extension:credBlob=true, webauthn:extension:largeBlob=true, webauthn:extension:minPinLength=true, webauthn:extension:prf=true, webauthn:virtualAuthenticators=true} 20:42:28.696 INFO [LocalSessionMap.add] - Added session to local Session Map, Id: 721500a671676dcf1e489c30f24eeb63, Node: http://<hostname/ip>:5555 20:42:28.697 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: 721500a671676dcf1e489c30f24eeb63 Caps: {acceptInsecureCerts=true, browserName=chrome, browserVersion=153.0.8010.52, chrome={chromedriverVersion=153.0.8010.52 (78e5e45d4bb41035e17ea4da2cc257f496416ac9-refs/branch-heads/8010@{#1443}), userDataDir=/tmp/org.chromium.Chromium.scoped_dir.prMD9q}, fedcm:accounts=true, goog:chromeOptions={debuggerAddress=localhost:34273}, goog:loggingPrefs={browser=SEVERE, driver=SEVERE, performance=SEVERE}, goog:processID=2416365, networkConnectionEnabled=false, pageLoadStrategy=normal, platformName=linux, proxy={}, se:bidiEnabled=false, se:cdp=ws://<hostname/ip>:4444/session/721500a671676dcf1e489c30f24eeb63/se/cdp, se:cdpVersion=153.0.8010.52, se:deleteSessionOnUi=true, setWindowRect=true, strictFileInteractability=false, timeouts={implicit=0, pageLoad=300000, script=30000}, unhandledPromptBehavior=dismiss and notify, webauthn:extension:cmtgKey=true, webauthn:extension:credBlob=true, webauthn:extension:largeBlob=true, webauthn:extension:minPinLength=true, webauthn:extension:prf=true, webauthn:virtualAuthenticators=true} 20:43:36.601 WARN [SeleniumSpanExporter$1.lambda$export$1] - {"traceId": "f0c7a5d2c4446dbb4522dbed58d27f44","eventTime": 1789933416601365709,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "<hostname/ip>:5555","http.method": "POST","http.request_content_length": "97","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession\u002fa1e2730d1cdbb375c0467503f33d7ddf\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.49.0 (java unix)"}} ... ... 01:14:54.594 WARN [SeleniumSpanExporter$1.lambda$export$1] - {"traceId": "08fe7db9db3b22d907f76128917f6f85","eventTime": 1789949694594158500,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "<hostname/ip>:5555","http.method": "POST","http.request_content_length": "97","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession\u002f721500a671676dcf1e489c30f24eeb63\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.49.0 (java unix)"}} ... 01:28:43.971 WARN [SeleniumSpanExporter$1.lambda$export$1] - {"traceId": "61d0f872f033096b3dc2304f0c92d8ec","eventTime": 1789950523970852102,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "<hostname/ip>:5555","http.method": "POST","http.request_content_length": "112","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession\u002f721500a671676dcf1e489c30f24eeb63\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.49.0 (java unix)"}} ... 01:28:44.566 INFO [LocalNode.stopTimedOutSession] - Session id 721500a671676dcf1e489c30f24eeb63 is stopping on demand... 01:28:44.566 INFO [SessionSlot.stop] - Stopping session 721500a671676dcf1e489c30f24eeb63 (reason: QUIT_COMMAND) 01:28:44.566 INFO [SessionSlot.stop] - Session stopped successfully: 721500a671676dcf1e489c30f24eeb63 ... 10:48:10.118 WARN [SpanWrappedHttpHandler.execute] - Unable to execute request: Cannot find session with id: 721500a671676dcf1e489c30f24eeb63 Build info: version: '4.49.0', revision: 'bedb24f bedb24f6f703876e7e4c5d506f0d697eb358c720' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '4.18.0-553.84.1.el8_10.x86_64', java.version: '17.0.17' Driver info: driver.version: unknown org.openqa.selenium.NoSuchSessionException: Cannot find session with id: 721500a671676dcf1e489c30f24eeb63 Build info: version: '4.49.0', revision: 'bedb24f bedb24f6f703876e7e4c5d506f0d697eb358c720' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '4.18.0-553.84.1.el8_10.x86_64', java.version: '17.0.17' Driver info: driver.version: unknown at org.openqa.selenium.grid.node.local.LocalNode.stop(LocalNode.java:1178) at org.openqa.selenium.grid.node.StopNodeSession.execute(StopNodeSession.java:38) at org.openqa.selenium.remote.http.Route$TemplatizedRoute.handle(Route.java:192) at org.openqa.selenium.remote.http.Route.execute(Route.java:69) at org.openqa.selenium.grid.security.RequiresSecretFilter.lambda$apply$0(RequiresSecretFilter.java:61) at org.openqa.selenium.remote.tracing.SpanWrappedHttpHandler.execute(SpanWrappedHttpHandler.java:87) at org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:63) at org.openqa.selenium.remote.http.Route$CombinedRoute.handle(Route.java:358) at org.openqa.selenium.remote.http.Route.execute(Route.java:69) at org.openqa.selenium.grid.node.Node.execute(Node.java:316)

The log entry "10:48:10.118 WARN [SpanWrappedHttpHandler.execute] - Unable to execute request: Cannot find session with id: 721500a671676dcf1e489c30f24eeb63" keeps repeating trying to remove the session

These will only clear after a restart.

vicozohili avatar Sep 22 '26 09:09 vicozohili

Thanks @vicozohili, that log helps a lot.

Reading it in order:

  • 20:42:28 the session is created on the Node and added to the Session Map. - 01:28:44 the Node logs "stopping on demand" with reason QUIT_COMMAND, then"Session stopped successfully". So the Node did stop the session and removed it. - From 10:48 onwards something keeps sending a DELETE for that session to the Node, which answers "Cannot find session" every time.

So it looks like the Node ends the session correctly, but the Hub never removes it from the Session Map and keeps treating it as live. If that's right, it isn't specific to the timeout: any way a session ends would leave it stale on the Hub, and the timeout config just made it visible.

One thing that would confirm it: after 01:28:44, is there any line like "Deleted session from local Session Map, Id: 721500a671676dcf1e489c30f24eeb63"? If that line never appears, the Hub never processed the close.

Since you can't roll back, I'll try to reproduce it with a separate hub and node on 4.49.0 and 4.44.0 and report back.

yashp676 avatar Sep 22 '26 10:09 yashp676

@yashp676 The log entry "Deleted session from local Session Map" does not exist for any session id that should already be closed in the logs.

FYI, i even added --delete-session-on-ui true to see if i can delete the sessions from the UI, but that also failed to delete the state sessions. Curl delete throws the same error could not find session id.

vicozohili avatar Sep 22 '26 10:09 vicozohili

Since the LocalNode.stop method is throwing a NoSuchSessionException despite the session appearing active in the grid state, it seems the session is being orphaned in the Session Map while the Node process has already cleared its internal reference. Have you checked the output of the /status endpoint to see if the session is still being reported by the Distributor, or if it only persists in the Session Map? It would be useful to know if the SessionMap is failing to receive or process the removal event from the Node when the timeout threshold is reached.

roberalani26 avatar Sep 22 '26 11:09 roberalani26

/status still has the session listed

vicozohili avatar Sep 22 '26 11:09 vicozohili

Thanks, that's useful. Assuming that's the Hub's /status on :4444, it comes from the Distributor, not the Session Map. Both components listen for SessionClosedEvent independently, and both missed it here. Since the Node stays registered, heartbeats over the event bus are clearly getting through, so it looks like the close event specifically isn't reaching the Hub or isn't being processed there.

Two quick checks that don't need a rollback:

Does the Node's own /status (:5555) still show that session in a slot, or is it free there while the Hub's (:4444) shows it occupied? Around 01:28:44 in the hub log, is there any WARN/SEVERE, e.g. a JSON/deserialization error or anything mentioning the event bus?

This also explains why delete from the UI or curl can't recover it: the delete goes to the Node, which no longer has the session and throws before any close event is sent. And if the Distributor still counts those slots as busy, the node gradually loses real capacity, which would explain needing daily restarts.

I'm setting up hub/node and standalone on 4.49.0 and 4.44.0 locally to confirm, then I'll narrow down the commit.

yashp676 avatar Sep 22 '26 11:09 yashp676

Hi @vicozohili,

Update from my side: I haven't been able to reproduce this locally on 4.49.0 (hub + node on Ubuntu). I tested:

  • normal quit
  • --session-timeout 60
  • your exact flags (-Dwebdriver.http.factory=jdk-http-client, --override-max-sessions true --max-sessions 20, --delete-session-on-ui true)
  • a Grid left idle for 10+ minutes before creating sessions - sessions that hit repeated 500s on execute/sync before quitting
  • 10 concurrent sessions
  • sessions sending the new se:remoteUrl capability

In every case the Hub logged Releasing slot and Deleted session from local Session Map with the correct reason, and sessionCount returned to 0.

Comparing my logs with yours, the Node side of the stop is identical (stopping on demand β†’ Stopping session (reason: QUIT_COMMAND) β†’ Session stopped successfully). The difference is that your Hub never logs Releasing slot / Deleted session afterwards. Since both the Session Map and the Distributor still show the session, it looks like the Hub stops processing session-closed events at some point in a long-running Grid.

Two things would help narrow it down, and neither needs a rollback. Could you capture them before your next restart?

1. When did cleanup stop?

grep -c "Added session to local Session Map" nohup.out
grep -c "Deleted session from local Session Map" nohup.out
grep "Deleted session from local Session Map" nohup.out | tail -1

If some sessions were cleaned up earlier and then it stopped, the log around the last successful cleanup may show what went wrong.

2. A thread dump of the hub while stale sessions exist:

kill -3 <hub-pid>

This doesn't stop the process; the dump is written to the hub's stdout (nohup.out in your setup). If a thread handling events is stuck, it will show up there. Please attach the dump, or at least the "Event Bus Poller" and "Message Bus Proxy" threads plus any threads in BLOCKED state.

One small suggestion: since hub and node are both started with nohup from the same directory, they're probably writing to the same nohup.out. After the next restart, redirecting each to its own file (e.g. > hub.log 2>&1 and > node.log 2>&1) would make these logs much easier to read.

yashp676 avatar Sep 22 '26 13:09 yashp676

The NoSuchSessionException during the LocalNode.stop execution suggests that the SessionMap and LocalNode states are becoming desynchronized, preventing the cleanup task from locating the session to terminate it. Are you seeing any concurrent SessionRejectedException or thread pool saturation logs in the event bus output immediately preceding the time when these sessions should have timed out?

ronniromeo26 avatar Sep 22 '26 14:09 ronniromeo26

The thread dump I asked for above would show thread pool saturation or a stuck event thread directly, so that should answer this. Note that the Node did stop the session successfully (01:28:44 in the reporter's log); the NoSuchSessionException comes from later DELETE attempts for a session the Node had already removed.

yashp676 avatar Sep 23 '26 10:09 yashp676

@yashp676 see attached session_trace.log

nohup.out.log

vicozohili avatar Sep 23 '26 17:09 vicozohili

Hi @vicozohili,

Thank you for providing the log file; it was really helpful.

A quick note on what I’m doing in parallel: since your log shows that cleanup works for roughly the first 10 hours of Hub uptime and then stops, I’ve started an 18-hour soak test on 4.49.0 locally β€” Hub + Node with --session-timeout 72000. I’m creating and quitting one short session every 15 minutes and checking each time whether the Hub logs Deleted session from local Session Map.

If it starts failing at some point, the test will automatically take a thread dump of the Hub so we can investigate where the Event Bus Poller thread is getting stuck.

I’ll report back either way. The two things from my previous comment would still help a lot, especially the first one, since it’s quick and doesn’t require a restart:

  1. Create a short session on the running Grid now and quit it immediately β€” does the Hub clean that one up, or does it also go stale?
  2. Take a thread dump of the Hub (kill -3 <hub-pid>) while the stale sessions are present.

yashp676 avatar Sep 23 '26 19:09 yashp676

The NoSuchSessionException in LocalNode.stop suggests the session map has lost track of the session ID while the node still considers it active; have you checked if the SessionMap internal state is being updated correctly when the jdk-http-client factory is used?

dredonjaquana26 avatar Sep 25 '26 01:09 dredonjaquana26

Update on the soak test: I've had a 4.49.0 hub + node running locally with 22 hours of continuous hub uptime, creating and quitting a short session every 15 minutes with --session-timeout 72000 (matching your config). All 72 sessions were cleaned up correctly β€” Releasing slot + Deleted session from local Session Map every time, with no failures at any point in that 22 hours.

That's well past the window where your grid broke: in your log the last successful cleanup was at ~10h09m of hub uptime, and the next stop at ~14h31m failed and never recovered.

So hub uptime alone doesn't reproduce it on an idle grid. Combined with my earlier tests (normal quit, session timeout, your exact flags, repeated 500s on execute/sync, 10 concurrent sessions, se:remoteUrl), I haven't been able to trigger it from the outside at all.

That makes your running grid the only place this is currently reproducible, so these two would really help:

  1. On the grid as it is now, create a short session and quit it immediately β€” does the Hub log Deleted session from local Session Map for it, or does it also go stale? This tells us whether the Hub has permanently stopped processing session-closed events or whether it's specific to certain sessions.

  2. A thread dump while stale sessions exist: kill -3 <hub-pid> (doesn't stop the process; output goes to nohup.out). For comparison, here's what the relevant thread looks like on a healthy hub:

   "Event Bus Poller" #24 daemon ... RUNNABLE
       at org.zeromq.ZMQ$Poller.poll(ZMQ.java:4251)
       at org.openqa.selenium.events.zeromq.UnboundZmqEventBus$PollingRunnable.run(UnboundZmqEventBus.java:251)

If on your hub that thread is somewhere else, or BLOCKED, that's almost certainly the cause.

One more thing that might matter: my setup had hub and node on the same box with nothing in between. Is that true for yours too, or do the hub and node sit on different machines with a firewall, load balancer or NAT between them? If anything can silently drop idle TCP connections on 4442/4443, a dead ZeroMQ SUB connection would explain exactly what we're seeing β€” published events would be lost while HTTP health checks keep the Node looking UP.

yashp676 avatar Sep 27 '26 07:09 yashp676

Yea, my setup also has hub and node running on the same server.

So I setup exactly the same selenium grid hub/node running on the same server, on two separate servers to capture the thread dump on both servers and in both servers, stale session remain on the grid UI although some session do clear as expected.

see attached nohup_server_1.out on this server, the sessions that still appear on the grid are: d45f688080c891eeeb7e5e1b20fc14d0 (active for 15hrs) 835cfcbf7a1f3beb7fea4db9c386ad40 (active for 17hrs) ae0c482de1dd579798c9a5089f9ff96a (active for 1d 15h)

see attached nohup_server_2.out on this server, the stale session are: ec5ede2a2bbe20124af4b184dec9031b (active for 15hrs) c7893c4717037cd5c827f8893074b443 (active for 16hrs)

The frameworks that initiated all of the above have all completed after calling driver.quit and I was expecting no sessions to be still active on the grid. If it is an isolated issue, should I be seeing the same behaviour on two separate servers. Let me know what you find in the attached thread dumps.

nohup_server_1.out.log nohup_server_2.out.log

vicozohili avatar Sep 28 '26 10:09 vicozohili

Hi @vicozohili , This is really useful β€” and to answer your question directly: no, two independent servers showing identical behaviour is not an isolated issue. I think we can also drop the "hub thread is stuck" theory, and the logs point somewhere different from where we've been looking.

1. Both hubs are completely healthy in the dumps.

On both servers: Event Bus Poller RUNNABLE and idle in ZMQ$Poller.poll β†’ UnboundZmqEventBus$PollingRunnable.run:251; Message Bus Proxy RUNNABLE and idle in the ZMQ proxy; both Event Bus Listener Notifier threads WAITING on an empty queue; zero BLOCKED threads. So while the stale sessions existed, the Hub had nothing queued and nothing stuck β€” those events never reached it.

2. The close events aren't lost β€” they're delivered hours late, in bursts.

Lining up every node-side stop against its hub-side Deleted session from local Session Map:

Server 1 (19 sessions)

Session Node stop Hub delete Lag
f82979ed … 3c70b832 (7) 19:42–01:39 same instant 1–6 ms
9bfe29cf 06:29:36 01:52:56 19.4 h
44d15ad2 20:42:40 01:53:02 5.2 h
170c1772 21:20:58 01:53:02 4.5 h
cd6c2eee 01:39:07 01:53:03 14 min
dde8a54a 06:36:59 01:32:06 18.9 h
499b32fb 20:42:29 01:32:07 4.8 h
19c2d7fe 21:16:55 01:32:07 4.3 h
aab1b69c, e44afc39 01:34:58 / 01:39:43 same instant 2 ms
ae0c482d, d45f6880, 835cfcbf 23:08:57 / 23:08:23 / 06:29:27 β€” never

Server 2 (6 sessions β€” not one prompt cleanup)

Session Node stop Hub delete Lag
c41547e8 05:04:09 01:58:03 20.9 h
4b6735cc 09:49:06 01:58:05 16.1 h
a835efbd 04:55:44 01:42:34 20.8 h
8d47fd7a 10:11:56 01:42:38 15.5 h
ec5ede2a, c7893c47 04:56:13 / 11:29:15 β€” never

The ones with no delete are exactly the sessions you listed as stale on each server. So "stale until restart" is really "stale until the next flush, which hadn't happened yet."

Three properties of those flushes:

  • Bursty β€” four deletes inside 7 seconds after hours of silence.
  • In node-stop order, oldest first β€” a queue draining, not independent retries.
  • With individual events dropped mid-sequence β€” in the 01:52 burst, 06:29 β†’ 20:42 β†’ 21:20 β†’ 01:39 were delivered but 23:08 was skipped; same shape in the 01:32 burst.

Ordered, batched, hours-late delivery with occasional losses looks much more like the event bus connection breaking and re-establishing (messages buffering, flushing on reconnect, some discarded) than like a Hub-side listener problem.

3. Server 2 shows the bus link dropping directly.

Its hub logged Switching Node 20e503c6… from DOWN to UP 14 times for the same Node UUID with no restart in between β€” it keeps losing the Node's heartbeats and regaining them. The 01:58 delete burst landed ~3 minutes after one of those transitions. Server 1 had no flapping and still had the delays, so it isn't required, but on server 2 it's direct evidence.

4. Separately: the Node-side stop also looks very late.

On server 2, 4b6735cc was created 18:45:42 and the Node only logged stopping on demand (reason: QUIT_COMMAND) at 09:49:06 β€” 15h later. c41547e8: created 19:58:02, stopped 05:04:09 (9h). With --session-timeout 72000 (20h) these aren't timeouts, and you say the frameworks called driver.quit() and completed. So the Node seems to sit on the quit for hours before acting on it, which on its own would explain the UI showing a session "active for 15hrs".

What would help next: the dumps you sent are from the Hub process (they contain Message Bus Proxy and the distributor threads). Since the Hub is demonstrably idle and healthy, the interesting one now is the Node β€” kill -3 <node-pid> while stale sessions exist. That should show whether the Node's publisher or its session cache is where these closes are parked.

Also, if it's easy: are the Hub and Node talking over localhost or over the machine's hostname/IP on 4442/4443? If it's the external interface, a local firewall or conntrack idle timeout reaping those long-lived ZMQ connections would fit this pattern exactly.

yashp676 avatar Sep 29 '26 12:09 yashp676

I think I've found the mechanism, though not yet the trigger. Posting now because it reframes the problem and there's a fix worth discussing either way.

Session close on the Node is asynchronous, on ForkJoinPool.commonPool().

In LocalNode (4.49.0, ~line 260):

this.currentSessions =
    Caffeine.newBuilder()
        .expireAfterAccess(sessionTimeout)
        .ticker(ticker)
        .removalListener(this::stopTimedOutSession)
        .build();

Caffeine delivers removalListener notifications via its executor, which defaults to ForkJoinPool.commonPool() β€” no .executor(...) is configured here. So LocalNode.stop(id) calls currentSessions.invalidate(id) and returns immediately, and everything that matters happens later on a common-pool task:

  • the "Session id … is stopping on demand..." log line
  • slot.execute(new HttpRequest(DELETE, "/session/" + id)) β€” blocking HTTP
  • slot.stop(closeReason, …) β†’ SessionSlot.stop:173 β†’ bus.fire(new SessionClosedEvent(...))

The Hub's LocalSessionMap:77 and LocalGridModel:74 both wait on that event. So if the common pool is saturated, closes are delayed arbitrarily, and the Node's log timestamp reflects when the listener ran, not when the quit arrived.

That matches @vicozohili's data precisely. From the two nohup files:

  • The "stopping on demand" line lands 9h and 15h after session creation, with --session-timeout 72000 (20h) β€” so these aren't timeouts, and the frameworks had already finished and called driver.quit().
  • Hub deletes arrive in bursts (four inside 7 seconds after hours of silence), in node-stop order, oldest first β€” a work queue draining, not retries.
  • On server 1, seven early sessions were cleaned up in 1–6 ms, then later ones lagged 14 min to 19.4 h, then two more were instant again. The pool being busy or idle at the moment of the quit explains the bimodality; a lost-event theory doesn't.

This is not the regression by itself. Caffeine has been in LocalNode since selenium-4.40.0 (08507ee118), well before the last-known-good 4.44.0, so something else in 4.45–4.48 must have started saturating or blocking that pool on the Node. 83b0c35e90 ("Apply the WebSocket frame fast path on the Node", which removed the executor hop from the Node's frame path) and 8d8cf6463a ("Close pre-handshake race in WebSocket proxy", which added a lock-guarded pre-handshake buffer) both change Node threading inside that window, and every affected session here advertises a se:cdp endpoint β€” but I haven't been able to tie either to the common pool yet.

Regardless of the trigger, dispatching session teardown β€” blocking HTTP plus a browser process kill β€” onto the shared commonPool looks like the wrong place for it. Two options:

  1. Caffeine.evictionListener(...) instead of removalListener(...), which runs synchronously on the removing thread (the pre-4.40 Guava behaviour).
  2. An explicit .executor(...) with a dedicated pool for session teardown.

I'm happy to prepare a PR for either β€” maintainers, do you have a preference? I'll also put together a before/after showing close latency under a constrained common pool.

Separately, a one-line bug in GuardedRunnable (java/src/org/openqa/selenium/concurrent/GuardedRunnable.java):

} catch (Exception e) {

LocalNode schedules currentSessions::cleanUp every 30s through this guard, and that task is what drives Caffeine expiry (no .scheduler(...) is set). An Error escapes this catch, and scheduleAtFixedRate then cancels the task permanently β€” after which the Node never expires a session again until restart, which is this issue's original symptom. The class javadoc says its purpose is to keep scheduleAtFixedRate working, so catch (Throwable) looks like the intent. Same code in 4.44.0, so it's not the regression either, but I'll open it as its own small PR.

@vicozohili β€” both thread dumps you sent are from the Hub process (they contain Message Bus Proxy and the distributor threads), and both are completely idle and healthy, which fits: the Hub was never the problem. If you can get one from the Node process while stale sessions exist (kill -3 <node-pid>), the thing to look for is the ForkJoinPool.commonPool-worker-* threads and whether anything is parked or blocked in stopTimedOutSession / SessionSlot.stop. That would identify the trigger.

yashp676 avatar Sep 29 '26 14:09 yashp676

Hi @yashp676 , attached is the node thread dump from both servers I have not restarted the grids yet on both servers, so the latest node thread dump should have appended to the previous log for the hub.

server_1_node_nohup.out.log server_2_node_nohup.out.log

vicozohili avatar Sep 29 '26 14:09 vicozohili

Thanks @vicozohili β€” the node dumps are very useful, and they rule out two things I was chasing (including one of my own).

The Node is entirely healthy. Uptime 97.2h on both, zero BLOCKED threads, Event Bus Poller idle in ZMQ$Poller.poll, Event Bus Publisher idle waiting for work, Event Bus Listener Notifier on an empty queue.

The 30-second session cleanup task is alive, so the GuardedRunnable gap I raised in #18091 is not what happened here:

Thread (both scheduled every 30s) Server 1 Server 2
Local Node - Session Cleanup cpu=388ms cpu=453ms
UploadTempFile Cleanup Node cpu=222ms cpu=204ms

Over ~11,600 executions the session cleanup has burned more CPU than its sibling on the same schedule β€” it's been running throughout. #18091 is still worth fixing on its own merits, but it isn't the cause of this.

There is no queued Caffeine removal work either. Neither Node dump has a single ForkJoinPool.commonPool-worker-* thread, while both Hub dumps do. So the async removalListener dispatch isn't backed up.

And the event bus never leaves the machine:

[UnboundZmqEventBus.<init>] - Connecting to tcp://0.0.0.0:4442 and tcp://0.0.0.0:4443

0.0.0.0 resolves to loopback, so Hub↔Node ZMQ traffic never touches a NIC. My earlier firewall/LB question is moot β€” scratch that.

So, putting the two sets of dumps together:

  • The Node stops the session and fires SessionClosedEvent (all five stale sessions have their stopping on demand β†’ (reason: QUIT_COMMAND) β†’ Session stopped successfully lines).
  • Nothing is stuck or queued on the Node β€” publisher idle, no pending removal work.
  • Nothing is stuck or queued on the Hub β€” poller idle, Event Bus Listener Notifier queue empty, zero BLOCKED.
  • Yet LocalSessionMap and LocalGridModel never see the event, sometimes for hours, sometimes never.

That points at events being lost or stalled inside the ZeroMQ transport itself, over loopback, between the Node's PUB (:4443) and the Hub's XSUB. Supporting this: server 2's Hub logged Switching Node … from DOWN to UP 14 times for the same Node UUID with no restart, so the ZMQ link is dropping and re-establishing repeatedly even on loopback. Messages published while a PUB socket has no live peer are silently discarded, which would explain the permanently-lost ones; the ones that arrive 15–21h later in ordered bursts look like a pipe draining after a reconnect.

Two suggestions, one for @vicozohili and one for maintainers:

@vicozohili β€” since your Hub and Node are on the same box, running standalone instead of hub + node would keep the event bus entirely in-process with no ZMQ hop at all. If that's viable for your setup it's both a diagnostic (does the staleness disappear?) and, if so, a workaround that removes the daily restart.

Maintainers β€” regardless of the transport bug, the Grid currently has no reconciliation path. The Distributor already health-checks each Node over HTTP every 120s and gets back its live sessions; if the Hub treated "Node no longer reports session X" as grounds to drop X from the Session Map and release the slot, a single lost event would self-heal within two minutes instead of persisting until restart. Right now the slots stay occupied forever, so a long-running Grid slowly loses real capacity. Happy to work on that if it sounds like the right shape β€” it'd be independent of whatever is dropping the events.

yashp676 avatar Sep 29 '26 15:09 yashp676