SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.11k stars 8.1k forks source link

[🐛 Bug]: Unable to create session, bind address port already in use #14257

Closed nidhintleo closed 1 month ago

nidhintleo commented 1 month ago

What happened?

I have a test automation setup with selenium in k8s version v1.28.3 and Have a Selenium hub(selenium/hub:4.20.0-20240425) , selenium node (selenium/node-docker:4.20.0-20240425) and when a test the hub send request to selenium node to spin up a browser container (selenium/standalone-chrome:4.20.0-20240425) by communicating with the docker daemon by using the config.toml file of selenium node.

i have already tried with new version of chrome image (126) but the issue is still there.

the tests will work smoothly but my issue is some times i got below error for random test cases

message": "Could not start a new session. Could not start a new session. Unable to start container: 1f3a8280424b0d3e23216b0d3be9059732ee5e7f096b04439611694099cbf9bc\ndriver failed programming external connectivity on endpoint optimistic_curie (89fffaa21818af9547dcae3b2b2e822769b5efcc02ead9008c9084821600acb1): failed to bind port 0.0.0.0:7946\u002ftcp: Error starting userland proxy: listen tcp4 0.0.0.0:7946: bind: address already in use \nHost info: host: 'node-docker1-6d6f5dc48-kgps7', ip: '10.233.125.187'\nBuild info: version: '4.20.0', revision: '866c76ca80'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-113-generic', java.version: '17.0.11'\nDriver info: driver.version: unknown\nBuild info: version: '4.20.0', revision: '866c76ca80'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-113-generic', java.version: '17.0.11'\nDriver info: driver.version: unknown"

the docker version is 27.0.3

in my knowledge the docker will pick a random free port to avoid conflicts then why its not picking the used port.? and how to fix this issue.?

How can we reproduce the issue?

its a random one.

Relevant log output

message": "Could not start a new session. Could not start a new session. Unable to start container: 1f3a8280424b0d3e23216b0d3be9059732ee5e7f096b04439611694099cbf9bc\ndriver failed programming external connectivity on endpoint optimistic_curie (89fffaa21818af9547dcae3b2b2e822769b5efcc02ead9008c9084821600acb1): failed to bind port 0.0.0.0:7946\u002ftcp: Error starting userland proxy: listen tcp4 0.0.0.0:7946: bind: address already in use \nHost info: host: 'node-docker1-6d6f5dc48-kgps7', ip: '10.233.125.187'\nBuild info: version: '4.20.0', revision: '866c76ca80'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-113-generic', java.version: '17.0.11'\nDriver info: driver.version: unknown\nBuild info: version: '4.20.0', revision: '866c76ca80'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-113-generic', java.version: '17.0.11'\nDriver info: driver.version: unknown"

value": {
        "error": "session not created",
        "message": "Could not start a new session. Could not start a new session. Unable to start container: db56c562e290492599c884dcb0443f28f8e213578e50a8fde87e00945ae786cb\ndriver failed programming external connectivity on endpoint elated_benz (edae185be76790c42c3de5e636bec418c1361f39ff75dbdef04ee9fd79946d4f): Bind for 0.0.0.0:3298 failed: port is already allocated \nHost info: host: 'node-docker3-8476bcd446-z4xz6', ip: '10.233.77.161'\nBuild info: version: '4.20.0', revision: '866c76ca80'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-113-generic', java.version: '17.0.11'\nDriver info: driver.version: unknown\nBuild info: version: '4.20.0', revision: '866c76ca80'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-113-generic', java.version: '17.0.11'\nDriver info: driver.version: unknown",

    WebDriverError: Unable to parse new session response: {
      "value": {
        "error": "session not created",
        "message": "Could not start a new session. Could not start a new session. Unable to start container: 709f167ac42990ba4468684b3d1db7ed7ff649bf6576b739b09b15009317b770\ndriver failed programming external connectivity on endpoint charming_heyrovsky (ee817b360fd656b590841380664f0a536f1f5943b289c556eaeaeb3d4c6b9f0c): Bind for 0.0.0.0:13620 failed: port is already allocated \nHost info: host: 'node-docker1-6d6f5dc48-kgps7', ip: '10.233.125.187'\nBuild info: version: '4.20.0', revision: '866c76ca80'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-113-generic', java.version: '17.0.11'\nDriver info: driver.version: unknown\nBuild info: version: '4.20.0', revision: '866c76ca80'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-113-generic', java.version: '17.0.11'\nDriver info: driver.version: unknown"

Operating System

Ubuntu 22.04

Selenium version

4.20

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

selenium/standalone-chrome:4.20.0-20240425

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

ChromeDriver 124.0.6367.78, Google Chrome 124.0.6367.78

Are you using Selenium Grid?

selenium/hub:4.20.0-20240425

github-actions[bot] commented 1 month ago

@nidhintleo, 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, MSEdgeDriver, 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!

diemol commented 1 month ago

But that error comes directly from your host environment. The container cannot start because the ports are busy. What have you checked to troubleshoot that?

nidhintleo commented 1 month ago

@diemol in my setup it will spin up only 8 containers maximum at a time but there is lot of free ports, even if the targeting port is used then why it is not find an other free port.?

diemol commented 1 month ago

Does this happen in every host you try? Does it also happen if you launch any other type of container that binds to a port?

nidhintleo commented 1 month ago

@diemol

I have four nodes. One node has the Selenium Hub, and the remaining three nodes have Selenium nodes (selenium/node-docker:4.20.0-20240425). These setups are with Kubernetes. Additionally, the same three worker nodes have Docker installed, and the browser containers are started by the Docker engine.

The Selenium node refers to the config.toml file to get the Docker daemon URL and the browser image. Below is the configuration:

config.toml

----------------

[docker]

Configs have a mapping between the Docker image to use and the capabilities that need to be matched to

start a container with the given image.

configs = [ "selenium/standalone-firefox:4.20.0-20240425", '{"browserName": "firefox", "platformName": "linux"}', "selenium/standalone-chrome:4.20.0-20240425", '{"browserName": "chrome", "platformName": "linux"}', "selenium/standalone-edge:4.20.0-20240425", '{"browserName": "MicrosoftEdge", "platformName": "linux"}' ]

URL for connecting to the docker daemon

url = "http://172.17.0.1:2375"

Docker image used for video recording

video-image = "selenium/video:latest" assets-path = "/opt/selenium/assets"

--------------------------

from this three machines am getting the same port conflict issues randomly. there is no other services are running on this nodes, also these nodes have 8vcpu and 32gb memory.

The issue have there is no port conflict patterns or a specific port range.

"Does it also happen if you launch any other type of container that binds to a port? "

No, if i start any other containers manually the docker will allot any free port to that containers the issue is getting only with the selenium.

diemol commented 1 month ago

Wait, are you using Dynamic Grid inside Kubernetes?

nidhintleo commented 1 month ago

@diemol

My application is running on Kubernetes so my selenium hub, Selenium nodes are in Kubernetes but both are static it is not scaling dynamically. only the browser containers are dynamic.

image

diemol commented 1 month ago

No, then why do you have these configs:

video-image = "selenium/video:latest"
assets-path = "/opt/selenium/assets"
url = "http://172.17.0.1:2375/"

That is for Dynamic Grid.

nidhintleo commented 1 month ago

That's right, we are using this config but the hub and nodes are on kubernetes and the browsers are spinning with docker.

diemol commented 1 month ago

So you are using Dynamic Grid on k8s, which we do not support. We recommend using the Keda integration seen in the Helm chart.

nidhintleo commented 1 month ago

@diemol

means this session not created issue is due to we are using Dynamic grid on k8s right ?

diemol commented 1 month ago

It means that we do not know how Dynamic Grid will behave in Kubernetes, which is why we offer the Keda integration with the helm chart.

diemol commented 1 month ago

I am closing this because there is no action item for us.

github-actions[bot] commented 4 days ago

This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.