question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: TimeoutException on closed NetworkInterceptor and quit driver

See original GitHub issue

What happened?

Summary

When a NetworkInterceptor and related WebDriver are closed/quit, the “CDP Connection” thread may eventually throw a TimeoutException.

This error occures a couple of seconds after the interceptor and driver have been closed/quit.

Here you can find a MCVE that is able to reproduce the error in at least 50% of the runs: https://github.com/tholewebgods/selenium-devtools-intercept-timeout-mcve (see the readme.md)

The code is reduced almost as much as possible for simplicity sake. The sleep is a replacement for a TestNG runner continuing to run further tests with new WebDriver sessions.

Guess

It looks like the CDP Connection thread is not informed of the interceptor shutdown and tries to handle communication that can no longer happen, finally running into a timeout.

Expectation

The CDP connection threads are

  1. either terminated when the interceptor or related driver were quit or

  2. brought into a state that allows the worker to either silently ignore timeouts or to log them as debug messages only to a proper logger. These exceptions should only be thrown by the thread runner if the interceptor is still open.

How can we reproduce the issue?

Here you can find a MCVE that is able to reproduce the error in at least 50% of the runs: https://github.com/tholewebgods/selenium-devtools-intercept-timeout-mcve (see the readme.md).

TL;DR:

1. Open an interceptor
2. Interact with the page
3. Close the interceptor
4. Close the driver
5. Wait > 10s

Relevant log output

org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException
Build info: version: '4.1.3', revision: '7b1ebf28ef'
System info: host: 'h001287568', ip: '10.208.2.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-192-generic', java.version: '11.0.16'
Driver info: driver.version: unknown
    at org.openqa.selenium.devtools.Connection.sendAndWait(Connection.java:161)
    at org.openqa.selenium.devtools.DevTools.send(DevTools.java:70)
    at org.openqa.selenium.devtools.idealized.Network.lambda$prepareToInterceptTraffic$4(Network.java:216)
    at org.openqa.selenium.devtools.Connection.lambda$handle$6(Connection.java:288)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
    at java.base/java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:442)
    at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1621)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
    at org.openqa.selenium.devtools.Connection.handle(Connection.java:257)
    at org.openqa.selenium.devtools.Connection.access$200(Connection.java:58)
    at org.openqa.selenium.devtools.Connection$Listener.lambda$onText$0(Connection.java:199)
    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: 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.devtools.Connection.sendAndWait(Connection.java:150)
    ... 19 more

Operating System

Ubuntu

Selenium version

4.1.3

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

Chrome 101 (Docker)

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

101.0 (Docker)

Are you using Selenium Grid?

4.4.0-20220812 (Docker)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pujaganicommented, Sep 28, 2022

Thank you for the details and the repo. I was able to reproduce the error. I am currently debugging to understand why it happens.

0reactions
github-actions[bot]commented, Nov 18, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't close browser in Remote Driver after timeout
i have following selenium Remote Driver code and when not found element, thrown error but browser doesn't closed. what could be reason and...
Read more >
Selenium Java Changelog - GitHub
* Fixing critical selenium server error caused by a user registering a driver class compiled with a higher Java version than the server...
Read more >
Index - Selenium
Close the current window, quitting the browser if it's the last window currently open. CLOSE - Static variable in interface org.openqa.selenium.remote.
Read more >
Selenium: java/CHANGELOG | Fossies
239 * Delete existing sessions if the Node is restarted. 240 * Sessions are now stopped when the Node is gracefully shutdown. 241...
Read more >
Error while closing Webdriver with Google Chrome
After my tests are running i am trying to give these command to close the chrome and web driver instance. ... webDriver.quit(); webDriver.close();...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found