SeleniumHQ / selenium

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

[🐛 Bug]: 'RejectedExecutionException' during Thread Local Test Execution after Selenium Java 4.14.0 #14269

Closed HasiniRangana closed 1 month ago

HasiniRangana commented 1 month ago

What happened?

When performing thread local test execution using Selenium Java 4.14.0, the following error occurs.

java.io.IOException: java.util.concurrent.RejectedExecutionException: Task jdk.internal.net.http.common.SequentialScheduler$SchedulableTask@6de2a772 rejected from java.util.concurrent.ThreadPoolExecutor@6c1e56ca[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 5]

Additional Information

In Selenium Java 4.14.0 CHANGELOG, there is a point as 'Shutdown executors created for a single tasks'. I think this causes issues for thread local test executions.

How can we reproduce the issue?

1. Initialize a Thread Local driver instance.
2. Submit multiple Selenium tasks for parallel execution.
3. Each task initializes a ChromeDriver and performs a simple operation.
4. Quit the Driver at the end of each task.
5. The RejectedExecutionException occurs intermittently during execution.

Relevant log output

java.io.IOException: java.util.concurrent.RejectedExecutionException: Task jdk.internal.net.http.common.SequentialScheduler$SchedulableTask@6de2a772 rejected from java.util.concurrent.ThreadPoolExecutor@6c1e56ca[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 5]

Operating System

Windows

Selenium version

Java 4.14.0

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

Chrome Version 126.0.6478.127

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

ChromeDriver 126.0.6478.126

Are you using Selenium Grid?

No

github-actions[bot] commented 1 month ago

@HasiniRangana, 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

We cannot fix old versions. Please try 4.22 and let us know how it goes. If you still find an issue, we need an automated script to reproduce it.

HasiniRangana commented 1 month ago

I tried with version 4.22.0. It had the same issue.

diemol commented 1 month ago

That's fine. We need a way to reproduce the issue. Please provide one.

github-actions[bot] commented 1 month ago

Hi, @HasiniRangana. Please follow the issue template, we need more information to reproduce the issue.

Either a complete code snippet and URL/HTML (if more than one file is needed, provide a GitHub repo and instructions to run the code), the specific versions used, or a more detailed description to help us understand the issue.

Note: If you cannot share your code and URL/HTML, any complete code snippet and URL/HTML that reproduces the issue is good enough.

Reply to this issue when all information is provided, thank you.

HasiniRangana commented 1 month ago

Actually this is running on selenium grid. And I have drill down the issue and found out that initializing the driver by below way causes the said issue when quitting.

driver.set((RemoteWebDriver) RemoteWebDriver.builder().address(GRID_URL).oneOf(capabilities).config(ClientConfig.defaultConfig().readTimeout(Duration.ofSeconds(CONNECTION_TIMEOUT))).build());

Reproducible code -


public void sample_test() throws MalformedURLException {
    ThreadLocal<RemoteWebDriver> driver = new ThreadLocal<>();
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setBrowserName("chrome");
    driver.set(new RemoteWebDriver(new URL("Grid URL"),capabilities));
    driver.get().get("https://www.google.com");
    driver.get().quit();
has context menu```

**Note - Initializing it like below doesn't causes this issue**

RemoteWebDriver driver = new RemoteWebDriver(new URL("Grid URL"),capabilities)
HasiniRangana commented 1 month ago

Hi @diemol , Are you able to look on this?

diemol commented 1 month ago

Not really.

If the issue happens when you use ThreadLocal<RemoteWebDriver> driver = new ThreadLocal<>();, isn't it more related to the way you are handling those threads?

diemol commented 1 month ago

We are closing this issue as we didn't get a reply from the original poster.

If someone is having this issue, please feel free to comment and provide a concise reproducible test case that includes the page required to execute the scenario (a sample page or a public site).

If you have any questions or need help, join us in the IRC/Slack channel, where the community can also assist you.

github-actions[bot] commented 1 week 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.