3

I am seeing a java.net.SocketException: Connection reset almost every time I use a driver.close() or driver.quit() statement. The browser does get closed and the exception isn't affecting any of my tests so far, but I would still like to understand why this is happening.

I checked for a version incompatibility, but the issue persists even after I updated my ChromeDriver. (I'm using ChromeDriver 84.0.4147.30 with Google Chrome Version 84.0.4147.105.)

The issue is intermittent, but usually occurs about 80% of the time.

Code:

public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver","/chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com/");
        driver.close();
        System.exit(0);
    }

Error:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 24445
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Aug 07, 2020 6:39:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Aug 07, 2020 6:39:14 PM org.openqa.selenium.remote.http.WebSocket$Listener onError
WARNING: Connection reset
java.net.SocketException: Connection reset
    at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:345)
    at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:376)
    at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
    at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133)
    at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:832)


Process finished with exit code 0
Mythreyi R.
  • 31
  • 1
  • 4
  • 1
    Getting the same error here with latest chromedriver and chrome (114.0.5735.90) and Selenium 4.10.0 – Lenny Primak Jul 12 '23 at 01:34
  • See answer https://stackoverflow.com/questions/72540689/how-to-help-this-org-openqa-selenium-remote-http-websocketlistener-onerror which worked for me – Lenny Primak Jul 12 '23 at 01:42

2 Answers2

-1

AS the name of exception suggest, there is issue in connection between your chromedriver and chrome browser.

Upgrade chrome browser to 84 and then retry or you can also download downgraded version of chromedriver which is compatible with your version of chrome.

Ankit Agrawal
  • 257
  • 1
  • 12
  • I saw this suggestion on a few pages and upgraded my chrome driver accordingly. But the exception still occurs even though my browser and chrome driver are compatible versions (both are version 84). Is there anything else I can check or modify to avoid this exception? – Mythreyi R. Aug 10 '20 at 08:52
  • Try these two checks and let me know if it resolves issue 1. see if your chromdriver is not left open. i think you should not get this issue on using driver.quit() 2. if you are still getting error, also check selenium-java version used in project. Make sure its latest stable version – Ankit Agrawal Aug 10 '20 at 09:24
  • not getting this issue in driver.quit(), but getting this issue in driver.close(), i have latest drivers too. – Uday May 16 '22 at 09:44
-2

I was also getting same error but it was resolved after changing selenium version.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – ethry Jul 06 '22 at 06:27
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/32177011) – Japhei Jul 09 '22 at 19:48