Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悰 Bug]: Set DriverSession TimeOut - Script throws timeout if the node is not available with in 3 minute #13884

Closed
gitissuepost opened this issue Apr 29, 2024 · 24 comments

Comments

@gitissuepost
Copy link

gitissuepost commented Apr 29, 2024

What happened?

I am using a grid on GKE where the node gets spinn up on-demand. Desired pod count for the deployment has been set as 0. As the script connects with teh grid, it spins up a POD to cater that request. However, the script fails as it doesn't get a node assgned with in 3 minutes.

I followed details mentioned in Issue-9314 to use WebDriverBuilder to set a higher timeout. However, the script leads to IllegalArgumentException: Base URI has already been set. Cannot also set driver service.

How can we reproduce the issue?

import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.service.DriverService;

import java.io.FileOutputStream;
import java.net.URL;
import java.time.Duration;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

public class TestDriverBuilder {
    public static void main(String[] args) {
        try {
            System.out.println(new Date());

            ChromeOptions options = new ChromeOptions();
            options.setPageLoadStrategy(PageLoadStrategy.EAGER);
            options.setAcceptInsecureCerts(true);
            options.addArguments("--disable-extensions", "--dns-prefetch-disable", "--disable-logging", "--remote-allow-origins=*");
            options.addArguments("--disable-dev-shm-usage", "--disable-infobars");
            options.addArguments("--unexpectedAlertBehaviour=dismiss", "--silent", "--blink-settings=imagesEnabled=false", "--inprivate");
            options.addArguments("--disable-blink-features", "--disable-blink-features=AutomationControlled", "--disable-gpu");
            options.addArguments("--no-sandbox", "--window-size=1920,1200", "--ignore-certificate-errors", "--disable-application-cache");

            Map<String, Object> chromePrefs = new HashMap<String, Object>();
            chromePrefs.put("download_restrictions", 3);
            options.setExperimentalOption("prefs", chromePrefs);

            LoggingPreferences logPrefs = new LoggingPreferences();
            logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
            options.setCapability("goog:loggingPrefs", logPrefs);

            DriverService.Builder serviceBuilder = new ChromeDriverService.Builder();
            ChromeDriverService chromeDriverService = (ChromeDriverService) serviceBuilder.build();
            chromeDriverService.sendOutputTo(new FileOutputStream(System.getProperty("user.dir") + "/target/driverlog"));

            WebDriver driver = (RemoteWebDriver) RemoteWebDriver
                    .builder()
                    .config(
                            ClientConfig.defaultConfig()
                                    .connectionTimeout(Duration.ofMinutes(10))
                                    .readTimeout(Duration.ofMinutes(10))
                                    .baseUrl(new URL("<GRID_HUB_URL>"))
                    )
//                    .withDriverService(chromeDriverService)
                    .addAlternative(options)
                    .build();
            driver.get("http://www.google.com");
            System.out.println(new Date());
            Thread.sleep(3000);
            driver.quit();
            System.out.println(new Date());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(new Date());
        }
    }
}

Relevant log output

Mon Apr 29 13:52:22 BST 2024
java.lang.IllegalArgumentException: Base URI has already been set. Cannot also set driver service.
	at org.openqa.selenium.remote.RemoteWebDriverBuilder.withDriverService(RemoteWebDriverBuilder.java:276)
	at TestDriverBuilder.main(TestDriverBuilder.java:53)
Mon Apr 29 13:52:23 BST 2024

Update added to Comment Below

Operating System

Windows10

Selenium version

Java 4.19.1

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

Chrome - Latest Docker Image

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

Grid - Docker - Chrome Node (GKE) - Latest

Are you using Selenium Grid?

4.20

Copy link

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

@gitissuepost
Copy link
Author

gitissuepost commented Apr 29, 2024

Commenting .withDriverService(chromeDriverService) triggered the test on grid. Hoever, it terminated after 3 minute without waiting further for the pod to be ready.

Mon Apr 29 14:18:26 BST 2024
Apr 29, 2024 2:21:42 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 124, returning the closest version; found: 123; Please update to a Selenium version that supports CDP version 124
org.openqa.selenium.remote.http.ConnectionFailedException: JdkWebSocket initial request execution error
Build info: version: '4.19.1', revision: 'abe0ee07dc'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.22'
Driver info: driver.version: unknown
	at org.openqa.selenium.remote.http.jdk.JdkHttpClient.openSocket(JdkHttpClient.java:243)
	at org.openqa.selenium.devtools.Connection.<init>(Connection.java:87)
	at org.openqa.selenium.devtools.SeleniumCdpConnection.<init>(SeleniumCdpConnection.java:36)
	at org.openqa.selenium.devtools.SeleniumCdpConnection.lambda$create$3(SeleniumCdpConnection.java:103)
	at java.base/java.util.Optional.map(Optional.java:265)
	at org.openqa.selenium.devtools.SeleniumCdpConnection.create(SeleniumCdpConnection.java:103)
	at org.openqa.selenium.devtools.SeleniumCdpConnection.create(SeleniumCdpConnection.java:49)
	at org.openqa.selenium.devtools.DevToolsProvider.getImplementation(DevToolsProvider.java:50)
	at org.openqa.selenium.devtools.DevToolsProvider.getImplementation(DevToolsProvider.java:29)
	at org.openqa.selenium.remote.Augmenter.augment(Augmenter.java:207)
	at org.openqa.selenium.remote.Augmenter.augment(Augmenter.java:178)
	at org.openqa.selenium.remote.RemoteWebDriverBuilder.build(RemoteWebDriverBuilder.java:369)
	at TestDriverBuilder.main(TestDriverBuilder.java:55)
Caused by: java.net.ConnectException
	at java.net.http/jdk.internal.net.http.common.Utils.toConnectException(Utils.java:1020)
	at java.net.http/jdk.internal.net.http.PlainHttpConnection.connectAsync(PlainHttpConnection.java:179)
	at java.net.http/jdk.internal.net.http.Http1Exchange.sendHeadersAsync(Http1Exchange.java:238)
	at java.net.http/jdk.internal.net.http.Exchange.lambda$responseAsyncImpl0$8(Exchange.java:435)
	at java.net.http/jdk.internal.net.http.Exchange.checkFor407(Exchange.java:367)
	at java.net.http/jdk.internal.net.http.Exchange.lambda$responseAsyncImpl0$9(Exchange.java:439)
	at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:930)
	at java.base/java.util.concurrent.CompletableFuture.uniHandleStage(CompletableFuture.java:946)
	at java.base/java.util.concurrent.CompletableFuture.handle(CompletableFuture.java:2268)
	at java.net.http/jdk.internal.net.http.Exchange.responseAsyncImpl0(Exchange.java:439)
	at java.net.http/jdk.internal.net.http.Exchange.responseAsyncImpl(Exchange.java:343)
	at java.net.http/jdk.internal.net.http.Exchange.responseAsync(Exchange.java:335)
	at java.net.http/jdk.internal.net.http.MultiExchange.responseAsyncImpl(MultiExchange.java:347)
	at java.net.http/jdk.internal.net.http.MultiExchange.lambda$responseAsyncImpl$7(MultiExchange.java:384)
	at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:930)
	at java.base/java.util.concurrent.CompletableFuture.uniHandleStage(CompletableFuture.java:946)
	at java.base/java.util.concurrent.CompletableFuture.handle(CompletableFuture.java:2268)
	at java.net.http/jdk.internal.net.http.MultiExchange.responseAsyncImpl(MultiExchange.java:374)
	at java.net.http/jdk.internal.net.http.MultiExchange.lambda$responseAsync0$2(MultiExchange.java:293)
	at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1072)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1705)
	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:834)
Caused by: java.nio.channels.UnresolvedAddressException
	at java.base/sun.nio.ch.Net.checkAddress(Net.java:131)
	at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:675)
	at java.net.http/jdk.internal.net.http.PlainHttpConnection.lambda$connectAsync$0(PlainHttpConnection.java:165)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.net.http/jdk.internal.net.http.PlainHttpConnection.connectAsync(PlainHttpConnection.java:167)
	... 23 more
Mon Apr 29 14:21:45 BST 2024

Process finished with exit code 0

@diemol
Copy link
Member

diemol commented Apr 29, 2024

If you use a ChromeDriverService it implies you are using the driver locally. Either use that one or the RemoteWebDriver but not together, that is why you see the error.

@diemol diemol closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
@gitissuepost
Copy link
Author

@diemol - I have removed that assignment and it started working (Updated a comment). But it didn't wait for the expected time before landing to exception. I will update the header to keep it aligned.

@gitissuepost gitissuepost changed the title [馃悰 Bug]: Set DriverSession TimeOut - Not working [馃悰 Bug]: Set DriverSession TimeOut - Script throws timeout if the node is not available with in 3 minute Apr 29, 2024
@diemol
Copy link
Member

diemol commented Apr 29, 2024

@gitissuepost looks like there are network configuration errors?

UnresolvedAddressException

Please double check your configuration and if you need help, please check our Slack channel https://www.selenium.dev/support/

@gitissuepost
Copy link
Author

@diemol - If it's network eror, should it not encounter immediately rather waiting for 3 minutes? My Ingress timeout has been set to 15 min though.

@gitissuepost
Copy link
Author

Same with ingress timeout for 100 minutes

image

@diemol
Copy link
Member

diemol commented Apr 29, 2024

@diemol - If it's network eror, should it not encounter immediately rather waiting for 3 minutes? My Ingress timeout has been set to 15 min though.

You have a 3 minute sleep

            driver.get("http://www.google.com");
            System.out.println(new Date());
            Thread.sleep(3000);
            driver.quit();

@gitissuepost
Copy link
Author

gitissuepost commented Apr 29, 2024

@diemol - If it's network eror, should it not encounter immediately rather waiting for 3 minutes? My Ingress timeout has been set to 15 min though.

You have a 3 minute sleep

            driver.get("http://www.google.com");
            System.out.println(new Date());
            Thread.sleep(3000);
            driver.quit();

@diemol
Well, Thread.sleep() accepts number in millis. Andthis is to pause my execution for 3 sec. Hence I rule out this point as a cause of 3 min exception. Also, If it reaches this point, then the console should print 2 date values befroe exception and ending with another date stamp.

@diemol
Copy link
Member

diemol commented Apr 30, 2024

You are right. My apologies. I misread the number.

But yeah, it is strange that it waits 3 minutes instead of the 10 minutes you configured.

It should not error immediately because that is the purpose of the connection timeout: wait until the initial connection is done. I am checking the code to understand why it times out after 3 minutes.

@diemol
Copy link
Member

diemol commented Apr 30, 2024

We were not setting a connection timeout when the web socket was being opened. The linked commit should fix that.

@gitissuepost
Copy link
Author

We were not setting a connection timeout when the web socket was being opened. The linked commit should fix that.

Thanks @diemol. I will wait for this to get published in next version.

@gitissuepost
Copy link
Author

gitissuepost commented May 2, 2024

@diemol - I tried with the snapshot build and it is waiting over 3 minutes now. The Pod is taking around 4 minutes to get ready to be consumed. However, as soon as the node is up and the execution is being assigned, I get the same exception.

I see the node is consumed as the grid shows 1/1 for session and I can vnc into that. Inside the node, I can see that the browser has launched, but it never redirected to google.com as I am expecting.

Moreover, the fix (linked commit) is more similar to the previous code. Hence, I am expecting 4.20.0 version should wait for specified timeout.

Can you help me with some pointers here based on your expertise?

I see the traffic is not an issue as I can connect to google from the pod
image

Also, I see the session had been created successfully in the chrome node.

image

Thanks again for all your support so far.. Please let me know if you require any additional logs.

Once it is sorted in the snapshot version, i will try the same solution in 4.20.0 to see if it was already there and it was my knowledge gap which led to this ticket.

@diemol
Copy link
Member

diemol commented May 2, 2024

I do not know. I think the pod might have different network settings than the container. For example, our images do not have curl by default.

What is the exception you are getting? If it is UnresolvedAddressException, I am not sure what has to be set or configured in your environment.

@gitissuepost
Copy link
Author

@diemol - I debugged and see it's failing in builder itself. It never reached the step to navigate to URL.
image
Here in the snippet, it fails at line 52 (2nd last breakpoint) where it is instantiating the driver object from RemoteWebDriverBuilder.

@gitissuepost
Copy link
Author

It is trying create a driver with below capability. Is it any capability, that is causing this issue?

{ "capabilities": { "firstMatch": [ { "browserName": "chrome", "pageLoadStrategy": "eager", "acceptInsecureCerts": true, "goog:chromeOptions": { "args": [ "--disable-extensions", "--dns-prefetch-disable", "--disable-logging", "--remote-allow-origins=*", "--disable-dev-shm-usage", "--disable-infobars", "--unexpectedAlertBehaviour=dismiss", "--silent", "--blink-settings=imagesEnabled=false", "--inprivate", "--disable-blink-features", "--disable-blink-features=AutomationControlled", "--disable-gpu", "--no-sandbox", "--window-size=1920,1200", "--ignore-certificate-errors", "--disable-application-cache" ], "extensions": [ ], "prefs": { "download_restrictions": 3 } }, "goog:loggingPrefs": { "performance": "ALL" } } ] } }

@diemol
Copy link
Member

diemol commented May 7, 2024

What error stacktrace do you get?

@gitissuepost
Copy link
Author

What error stacktrace do you get?

org.openqa.selenium.remote.http.ConnectionFailedException: JdkWebSocket initial request execution error
Build info: version: '4.20.0', revision: '866c76ca80'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.22'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.http.jdk.JdkHttpClient.openSocket(JdkHttpClient.java:243)
at org.openqa.selenium.devtools.Connection.(Connection.java:87)
at org.openqa.selenium.devtools.SeleniumCdpConnection.(SeleniumCdpConnection.java:36)
at org.openqa.selenium.devtools.SeleniumCdpConnection.lambda$create$3(SeleniumCdpConnection.java:103)
at java.base/java.util.Optional.map(Optional.java:265)
at org.openqa.selenium.devtools.SeleniumCdpConnection.create(SeleniumCdpConnection.java:103)
at org.openqa.selenium.devtools.SeleniumCdpConnection.create(SeleniumCdpConnection.java:49)
at org.openqa.selenium.devtools.DevToolsProvider.getImplementation(DevToolsProvider.java:50)
at org.openqa.selenium.devtools.DevToolsProvider.getImplementation(DevToolsProvider.java:29)
at org.openqa.selenium.remote.Augmenter.augment(Augmenter.java:207)
at org.openqa.selenium.remote.Augmenter.augment(Augmenter.java:178)
at org.openqa.selenium.remote.RemoteWebDriverBuilder.build(RemoteWebDriverBuilder.java:369)
at TestDriverBuilder.main(TestDriverBuilder.java:52)
Caused by: java.net.ConnectException
at java.net.http/jdk.internal.net.http.common.Utils.toConnectException(Utils.java:1020)
at java.net.http/jdk.internal.net.http.PlainHttpConnection.connectAsync(PlainHttpConnection.java:179)
at java.net.http/jdk.internal.net.http.Http1Exchange.sendHeadersAsync(Http1Exchange.java:238)
at java.net.http/jdk.internal.net.http.Exchange.lambda$responseAsyncImpl0$8(Exchange.java:435)
at java.net.http/jdk.internal.net.http.Exchange.checkFor407(Exchange.java:367)
at java.net.http/jdk.internal.net.http.Exchange.lambda$responseAsyncImpl0$9(Exchange.java:439)
at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:930)
at java.base/java.util.concurrent.CompletableFuture.uniHandleStage(CompletableFuture.java:946)
at java.base/java.util.concurrent.CompletableFuture.handle(CompletableFuture.java:2268)
at java.net.http/jdk.internal.net.http.Exchange.responseAsyncImpl0(Exchange.java:439)
at java.net.http/jdk.internal.net.http.Exchange.responseAsyncImpl(Exchange.java:343)
at java.net.http/jdk.internal.net.http.Exchange.responseAsync(Exchange.java:335)
at java.net.http/jdk.internal.net.http.MultiExchange.responseAsyncImpl(MultiExchange.java:347)
at java.net.http/jdk.internal.net.http.MultiExchange.lambda$responseAsyncImpl$7(MultiExchange.java:384)
at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:930)
at java.base/java.util.concurrent.CompletableFuture.uniHandleStage(CompletableFuture.java:946)
at java.base/java.util.concurrent.CompletableFuture.handle(CompletableFuture.java:2268)
at java.net.http/jdk.internal.net.http.MultiExchange.responseAsyncImpl(MultiExchange.java:374)
at java.net.http/jdk.internal.net.http.MultiExchange.lambda$responseAsync0$2(MultiExchange.java:293)
at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1072)
at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run$$$capture(CompletableFuture.java:1705)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java)
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:834)
Caused by: java.nio.channels.UnresolvedAddressException
at java.base/sun.nio.ch.Net.checkAddress(Net.java:131)
at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:675)
at java.net.http/jdk.internal.net.http.PlainHttpConnection.lambda$connectAsync$0(PlainHttpConnection.java:165)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.net.http/jdk.internal.net.http.PlainHttpConnection.connectAsync(PlainHttpConnection.java:167)
... 24 more

@diemol
Copy link
Member

diemol commented May 7, 2024

UnresolvedAddressException

Still getting this.

How are you setting the grid-url?

@gitissuepost
Copy link
Author

I am configuring it using the attached config
selenium-grid-config.txt

I get this exception even when I have a node available to consume. I see the request is being assigned to the node but the driver is not being initialized.

@diemol
Copy link
Member

diemol commented May 7, 2024

The problem is that it needs to establish a WebSocket connection to the Grid URL. Can you check that WebSocket traffic is allowed?

@gitissuepost
Copy link
Author

@diemol - I am exploring that option to see how to check that in GKE. However, I tried running the command using the public ip and got below error
image

@diemol
Copy link
Member

diemol commented May 7, 2024

How can you fix that?

@gitissuepost
Copy link
Author

How can you fix
@diemol - Honestly, I don't know.. I am still exploring the options and checking if it's how GKE behave. I have logged a case with google cloud support understand more. I will try the same solution on EKS to see what additional settings, do I need to add to my config.

Moreover, I will try setting up the same on GKE using helm and see if it resolves everything..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants