selenium: Java selenium threads are not getting destroyed on driver.quit

What happened?

I’m encountering some unusual issues with the Selenium driver in Java. Our application collects and stores data from the user interface using Selenium automation scripts. This automated process runs about 300 to 400 times per day, executing correctly and storing data in the database as expected.

However, after the Java service has been running for more than a week, it begins to throw the error “Unable to create a new thread,” eventually leading to an out-of-memory exception on the server. To resolve this, I have to restart the Java service. After a restart, it works for a few more days before the same thread error and out-of-memory exception occur again.

Through debugging, I’ve observed that Selenium-related threads remain in the thread chain even after being closed with the driver.quit() statement in the finally block. Despite attempts to interrupt these threads, they persist, appearing as sleeping or zombie threads in the live threads list.

Has anyone faced similar issues or know of any fixes?

Java version: 17 Selenium version: 4.16.0

How can we reproduce the issue?

Even with basic chrome driver launch and quit will reproduce the thread issue. Threads details can be tracked through using JVisualVm or Jconsole

Relevant log output

Unable to create a thread

Operating System

Windows and unix

Selenium version

Java 17.0, Selenium 4.16 .0

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

Chrome 123

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

Chrome 123

Are you using Selenium Grid?

4.16.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 37 (17 by maintainers)

Most upvoted comments

@Togin I was currently debugging something else and stumbled into a case where the httpclient is not closed. Do you see errors while creating sessions (log message is: “Error while creating session with the driver service”)? In this case the httpclient is leaked.