SeleniumHQ / selenium

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

[🐛 Bug]: Could not start a new session. java.util.concurrent.TimeoutException #14412

Open jjqi92 opened 3 weeks ago

jjqi92 commented 3 weeks ago

What happened?

when create session via remoteWebDriver(), it throws an exception: Unable to create session: Could not start a new session. java.util.concurrent.TimeoutException

How can we reproduce the issue?

ChromeOptions options1 = new ChromeOptions();
options1.addArguments("--headless");
options1.addArguments("--window-size=1920,1080");
options1.addArguments("--no-sandbox");
options1.addArguments("--disable-dev-shm-usage");
ProxyConfig proxyConfig = new ProxyConfig();
options1.addArguments(String.format("--proxy-server=http://%s:%s", proxyConfig.getValueByKey("PROXY_HOST"), proxyConfig.getValueByKey("PROXY_PORT")));
driver = new RemoteWebDriver(new URL("http://10.119.101.54:4444"), options1);

Relevant log output

Some log for hub:
11:05:30.396 INFO [LocalDistributor.newSession] - Session request received by the Distributor:
 [Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless, --window-size=1920,1080, --no-sandbox, --disable-dev-shm-usage, --proxy-server=http://ntpro...], extensions: []}}]
11:06:14.272 INFO [Node.<init>] - Binding additional locator mechanisms: relative
11:07:14.305 INFO [Node.<init>] - Binding additional locator mechanisms: relative
11:08:14.259 INFO [Node.<init>] - Binding additional locator mechanisms: relative
11:08:30.404 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "2bf9ba90d84f3d93cba0cbe24d7f5a5e","eventTime": 1724123130395671697,"eventName": "Session request received by the Distributor","attributes": {"logger": "org.openqa.selenium.grid.distributor.local.LocalDistributor","request.payload": "[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless, --window-size=1920,1080, --no-sandbox, --disable-dev-shm-usage, --proxy-server=http:\u002f\u002fntpro...], extensions: []}}]"}}

11:08:30.405 WARN [SeleniumSpanExporter$1.lambda$export$1] - Unable to create session: Could not start a new session. java.util.concurrent.TimeoutException
Build info: version: '4.17.0', revision: 'e52b1be057*'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.80-trip20240626.el9.x86_64', java.version: '11.0.14.1'
Driver info: driver.version: unknown
Host info: host: 'r100021942-71111192-0', ip: '10.119.101.54'
11:08:30.407 WARN [SeleniumSpanExporter$1.lambda$export$1] - org.openqa.selenium.SessionNotCreatedException: Could not start a new session. java.util.concurrent.TimeoutException
Build info: version: '4.17.0', revision: 'e52b1be057*'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.80-trip20240626.el9.x86_64', java.version: '11.0.14.1'
Driver info: driver.version: unknown
Host info: host: 'r100021942-71111192-0', ip: '10.119.101.54'
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:655)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:570)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:830)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:790)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException
Build info: version: '4.17.0', revision: 'e52b1be057*'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.80-trip20240626.el9.x86_64', java.version: '11.0.14.1'
Driver info: driver.version: unknown
        at org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute0(JdkHttpClient.java:402)
        at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
        at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:55)
        at org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute(JdkHttpClient.java:358)
        at org.openqa.selenium.remote.tracing.TracedHttpClient.execute(TracedHttpClient.java:54)
        at org.openqa.selenium.grid.security.AddSecretFilter.lambda$apply$0(AddSecretFilter.java:40)
        at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:55)
        at org.openqa.selenium.grid.node.remote.RemoteNode.newSession(RemoteNode.java:130)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:651)
        ... 6 more
Caused by: java.util.concurrent.TimeoutException
        at java.base/java.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1886)
        at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2021)
        at org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute0(JdkHttpClient.java:385)
        ... 14 more

11:08:30.408 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "2bf9ba90d84f3d93cba0cbe24d7f5a5e","eventTime": 1724123310402541806,"eventName": "exception","attributes": {"exception.message": "Unable to create session: Could not start a new session. java.util.concurrent.TimeoutException\nBuild info: version: '4.17.0', revision: 'e52b1be057*'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.80-trip20240626.el9.x86_64', java.version: '11.0.14.1'\nDriver info: driver.version: unknown \nHost info: host: 'r100021942-71111192-0', ip: '10.119.101.54'","exception.stacktrace": "org.openqa.selenium.SessionNotCreatedException: Could not start a new session. java.util.concurrent.TimeoutException\nBuild info: version: '4.17.0', revision: 'e52b1be057*'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.80-trip20240626.el9.x86_64', java.version: '11.0.14.1'\nDriver info: driver.version: unknown \nHost info: host: 'r100021942-71111192-0', ip: '10.119.101.54'\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:655)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:570)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:830)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:790)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base\u002fjava.lang.Thread.run(Thread.java:829)\nCaused by: org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException\nBuild info: version: '4.17.0', revision: 'e52b1be057*'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.80-trip20240626.el9.x86_64', java.version: '11.0.14.1'\nDriver info: driver.version: unknown\n\tat org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute0(JdkHttpClient.java:402)\n\tat org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)\n\tat org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:55)\n\tat org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute(JdkHttpClient.java:358)\n\tat org.openqa.selenium.remote.tracing.TracedHttpClient.execute(TracedHttpClient.java:54)\n\tat org.openqa.selenium.grid.security.AddSecretFilter.lambda$apply$0(AddSecretFilter.java:40)\n\tat org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:55)\n\tat org.openqa.selenium.grid.node.remote.RemoteNode.newSession(RemoteNode.java:130)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:651)\n\t... 6 more\nCaused by: java.util.concurrent.TimeoutException\n\tat java.base\u002fjava.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1886)\n\tat java.base\u002fjava.util.concurrent.CompletableFuture.get(CompletableFuture.java:2021)\n\tat org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute0(JdkHttpClient.java:385)\n\t... 14 more\n","exception.type": "org.openqa.selenium.SessionNotCreatedException","logger": "org.openqa.selenium.grid.distributor.local.LocalDistributor","request.payload": "[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless, --window-size=1920,1080, --no-sandbox, --disable-dev-shm-usage, --proxy-server=http:\u002f\u002fntpro...], extensions: []}}]"}}

For Node:
[root@r100021942-71111186-0 bin]# java --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true -jar selenium-server-4.23.0.jar node --driver-configuration display-name="Chrome" max-sessions=10 webdriver-path="/usr/bin/chromedriver" stereotype='{"browserName":"chrome"}' --detect-drivers false --hub http://10.119.101.54:4444
11:01:43.319 INFO [LoggingOptions.configureLogEncoding] - Using the system default encoding
11:01:43.329 INFO [OpenTelemetryTracer.createTracer] - Using OpenTelemetry for tracing
11:01:43.601 INFO [UnboundZmqEventBus.<init>] - Connecting to tcp://10.119.101.54:4442 and tcp://10.119.101.54:4443
11:01:43.710 INFO [UnboundZmqEventBus.<init>] - Sockets created
11:01:44.714 INFO [UnboundZmqEventBus.<init>] - Event bus ready
11:01:44.900 INFO [NodeServer.createHandlers] - Reporting self as: http://10.119.101.49:5555
11:01:44.952 INFO [NodeOptions.getSessionFactories] - Detected 32 available processors
11:01:45.095 INFO [NodeOptions.report] - Adding Chrome for {"browserName": "chrome","platformName": "linux"} 10 times
11:01:45.208 INFO [Node.<init>] - Binding additional locator mechanisms: relative
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/opt/tomcat/bin/selenium-server-4.23.0.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
11:01:45.543 INFO [NodeServer$1.start] - Starting registration process for Node http://10.119.101.49:5555
11:01:45.546 INFO [NodeServer.execute] - Started Selenium node 4.23.0 (revision 4df0a231af): http://10.119.101.49:5555
11:01:45.613 INFO [NodeServer$1.lambda$start$1] - Sending registration event...
11:01:46.079 INFO [NodeServer.lambda$createHandlers$2] - Node has been added
11:07:02.459 WARN [SeleniumManager.lambda$runCommand$1] - Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)
11:07:02.465 WARN [SeleniumManager.lambda$runCommand$1] - Error sending stats to Plausible: error sending request for url (https://plausible.io/api/event)
11:07:03.329 INFO [LocalNode.newSession] - Session created by the Node. Id: 3fa876dfe5f317469f924fe3e4837d60, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome-headless-shell, browserVersion: 124.0.6367.118, chrome: {chromedriverVersion: 124.0.6367.78 (a087f2dd364d..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:36717}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://10.119.101.54:4444/ses..., se:cdpVersion: 124.0.6367.118, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
11:10:30.577 WARN [SeleniumManager.lambda$runCommand$1] - Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)
11:10:31.016 INFO [LocalNode.newSession] - Session created by the Node. Id: 93ab2f3b87fae926531ab33f4604f31f, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome-headless-shell, browserVersion: 124.0.6367.118, chrome: {chromedriverVersion: 124.0.6367.78 (a087f2dd364d..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:46883}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://10.119.101.54:4444/ses..., se:cdpVersion: 124.0.6367.118, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
11:12:15.268 INFO [LocalNode.stopTimedOutSession] - Session id 3fa876dfe5f317469f924fe3e4837d60 timed out, stopping...
11:12:15.359 INFO [SessionSlot.stop] - Stopping session 3fa876dfe5f317469f924fe3e4837d60

Operating System

ubuntu

Selenium version

java 4.23.0

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

chrome 124

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

chromedriver 124

Are you using Selenium Grid?

hub: 4.17.0 node:4.23.0

github-actions[bot] commented 3 weeks ago

@jjqi92, 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!

jjqi92 commented 3 weeks ago

14:20:05.060 WARN [SeleniumManager.lambda$runCommand$1] - Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json) 14:20:05.962 INFO [LocalNode.newSession] - Session created by the Node. Id: 8489e07ec24f11223e4bad9514b5257e, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome-headless-shell, browserVersion: 124.0.6367.118, chrome: {chromedriverVersion: 124.0.6367.78 (a087f2dd364d..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:42389}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://10.119.101.54:4444/ses..., se:cdpVersion: 124.0.6367.118, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}

pujagani commented 3 weeks ago

Is it running without using a proxy? Can you please try that? Then it might be the proxy that prevents the request from going through, hence the timeout.

jjqi92 commented 3 weeks ago
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
ProxyConfig proxyConfig = new ProxyConfig();
options.setAcceptInsecureCerts(false);
options.setEnableDownloads(false);
options.setProxy(new Proxy().setHttpProxy(String.format("http://%s:%s", proxyConfig.getValueByKey("PROXY_HOST"), proxyConfig.getValueByKey("PROXY_PORT"))));
WebDriver driver = new RemoteWebDriver(new URL("http://10.119.101.54:4444/wd/hub"), options);

After changing the proxy to the above method, RemoteWebDriver successfully initialized the driver, but an error occurred in driver.get("https://www.baidu.com") timeout: Timed out receiving message from renderer: -0.012 (Session info: chrome-headless-shell=124.0.6367.118)

Can you help me find out what's causing this?

pujagani commented 3 weeks ago

Thank you for trying it out. Can you try "options.addArguments("--headless=new");" and see if that helps? To understand how it is better read here https://developer.chrome.com/docs/chromium/new-headless.

jjqi92 commented 3 weeks ago

I later tried selenium-server-4.5.3.jar to configure the environment, but still couldn't open the url. Finally, after changing to selenium-server-standalone-3.141.59.jar, the problem was solved.

i will try "options.addArguments("--headless=new");" later. thank you.

diemol commented 3 weeks ago

Using selenium-server-standalone-3.141.59.jar is not really a solution as that a version not maintained anymore.

jjqi92 commented 3 weeks ago

Yes, I also hope to use selenium grid4, and my Java service also uses selenium4, but when I build a distributed cluster, I can't open the url in the browser. I also tried selenium server 4.23.0, 4.17. 0, 4.5.3 and other versions failed to solve the problem until I changed to 3.141.59.