Too Many Open Files (Selenium + PhantomJSDriver) Too Many Open Files (Selenium + PhantomJSDriver) selenium selenium

Too Many Open Files (Selenium + PhantomJSDriver)


The resource usage is caused by BrowserMob. To close the proxy and clean-up its resources, one must call stop().

For this client that means modifying the shutdown method

def shutdown() = {  mobProxy.stop()  driver.close()  driver.quit()}

Another method, abort, offers immediate termination of the proxy server and does not wait for traffic to cease.


In my opinion it seems a problem of PhantomJS. You can try the following alternatives:

  1. Use phantomjs 2.5.0-beta. It has been recently released. I'm not sure if this upgrade solves your problem, but at least it is worth to give a try. According to the changelog, the new features of this version are:

    • Upgrade QtWebKit to QtWebKitNG
    • Upgraded Qt to 5.7.1
  2. Clean the phantomjs processes after closing webdriver. You can implement your own cleaner to force that phantomjs is actually closed after driver.close() (invoking killall -9 phantomjs or similar).