selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🐛 Bug]: Selenium 4 "Failed to establish a new connection" exception when 250 webdrivers created using Python

Open bott17 opened this issue 4 years ago • 3 comments

What happened?

When you try to create and keep alive, around 250 webdrivers at the same time an exception is shown. This doesn't happen with Selenium 3. I reproduce it using remote drivers with a Selenium grid with version 4.1.0 just because I can't create this number of drivers on my local machine so I'm not sure if the issue is reproduced with local drivers or just with remotes. But, in both scenarios (using in my local Selenium 3: work, or Selenium 4:issue) I'm using the v4.1.0 in the Grid

Looking in to the code i found the issue is located with the new funcion _get_connection_manager() https://github.com/SeleniumHQ/selenium/blob/d7dfe5ec604faae440cc0be2c088c8ba9b92804f/py/selenium/webdriver/remote/remote_connection.py#L131

How can we reproduce the issue?

With Selenium 4.1.0 in your local, try to create 250 remote webdrivers without closing anyone first, using a Selenium grid v4.1.0

Relevant log output

File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 268, in __init__
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 359, in start_session
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 422, in execute
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/selenium/webdriver/remote/remote_connection.py", line 421, in execute
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/selenium/webdriver/remote/remote_connection.py", line 443, in _request
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/request.py", line 78, in request
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/request.py", line 170, in request_encode_body
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/poolmanager.py", line 375, in urlopen
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 783, in urlopen
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 783, in urlopen
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 783, in urlopen
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
  File "/Users/user/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/util/retry.py", line 574, in increment
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='x.x.x.x', port=yyyy): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10bbc0400>: Failed to establish a new connection: [Errno 24] Too many open files'))

Operating System

macOS Monterey

Selenium version

Selenium 4.1.0

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

Chrome 97

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

ChromeDriver 97.0.4692.71

Are you using Selenium Grid?

4.1.0

bott17 avatar Jan 24 '22 10:01 bott17

@bott17, 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 Jan 24 '22 10:01 github-actions[bot]

I think I found the cause. In Selenium 4 keep_alive option is set as True by default when creating the driver, different from Selenium 3. It looks like python can not handle this number of webdrivers with the keep_alive set to True, I reproduced the same issue using Selenium 3 and with this option as to True.

The issue can be closed, thanks

bott17 avatar Jan 24 '22 14:01 bott17

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 Feb 24 '22 00:02 github-actions[bot]