How can I give sessions in a Selenium Grid an unlimited idle time, but clean up disconnected ones?

417 views
Skip to first unread message

Chris König

unread,
Nov 3, 2015, 5:27:08 AM11/3/15
to Selenium Users

I have a selenium grid that uses the following config:

{
  "port": 4444,
  "newSessionWaitTimeout": 2000
}


and 2 nodes that use this config:

{
  "capabilities": [{
    "browserName": "chrome",
    "platform": "LINUX",
    "maxInstances": 8
  }],
  "configuration": {
    "nodeTimeout": 120,
    "port": 5555,
    "hubPort": 4444,
    "hubHost": "hubhost",
    "nodePolling": 2000,
    "registerCycle": 10000,
    "register": true,
    "cleanUpCycle": 2000,
    "timeout": -1,
    "browserTimeout": -1,
    "maxSession": 8
  }
}


I wrote a piece of Java-Code that opens a connection via the RemoteWebDriver-Class. The code does several calls on the driver and afterwards suspends for unknown time (30s - 1h). I don't want to close the session, because on wake, the process needs to react really fast.

With the timeout set to -1 everything works. The process will stay connected to the session (and the browser) for unlimited time. Unfortunately the process is killed at random, when an automatic service decides to. The node recognizes that the client shuts down:


selenium deleted due to client timeout


But the sessions aren't cleaned up! The unlimited timeout keeps them alive and the grid won't free them for further use.

How can I solve this problem with the selenium config?

Building a process-shutdown-hook that calls "driver.quit()" to free the session, is not an option.

Thanks for any help!

Krishnan Mahadevan

unread,
Nov 3, 2015, 5:43:16 AM11/3/15
to Selenium Users
Chris,
In short, you cannot solve this problem because of the way in which your tests are being orchestrated.

Since you have configured your Grid and node to never cleanup a browser when it detects that the browser is idle (you set a browserTimeout value to -1), Grid/node is never going to kick off the cleanup logic which otherwise would have cleaned up your idle browser and along with it, cleaned up the corresponding session for it.

Now you state that your client (I am assuming that it is your test code) is getting killed on an adhoc basis due to some reason (per you, an automatic service that is doing this). So when the client goes off, the client never informs the Grid to clean up the test sessions that it created. And since you literally disabled server side cleanup , you are stuck with stale sessions which will never let go of the resources.

Given the predicament, your only option is to employ a shutdown hook which basically ensures that all test sessions that were created by your client, are cleaned up just before the JVM exits as well.

I don't see any other mechanism of doing this.

The other option you can consider is to define a definite value for your browserTimeout rather than permanently disable it with a value of -1

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7ea9b5dc-b2b6-4b53-a47b-11f9f7042b5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages