0

I am using chromedriver but am sometimes getting the following errors:

03:34:09.188 [AsyncHttpClient-1-2] WARN org.openqa.selenium.remote.http.WebSocket - Connection reset
2022-01-05 21:34:09java.net.SocketException: Connection reset
2022-01-05 21:34:09at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:367)
2022-01-05 21:34:0903:34:09.180 [AsyncHttpClient-1-2] WARN org.asynchttpclient.netty.handler.WebSocketHandler - onError
2022-01-05 21:34:09java.net.SocketException: Connection reset
2022-01-05 21:34:09at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:367)
2022-01-05 21:34:09at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:398)
2022-01-05 21:34:09at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
2022-01-05 21:34:09at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1134)
2022-01-05 21:34:09at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
2022-01-05 21:34:09at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
2022-01-05 21:34:09at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
2022-01-05 21:34:09at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
2022-01-05 21:34:09at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
2022-01-05 21:34:09at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
2022-01-05 21:34:09at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
2022-01-05 21:34:09at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
2022-01-05 21:34:09at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
2022-01-05 21:34:09at java.base/java.lang.Thread.run(Thread.java:832)

I have:

ARG CHROME_VERSION=96.0.4664.45-1
ARG CHROME_DRIVER_VERSION=96.0.4664.45

and I am using selenium 4:

<dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>4.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>4.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>4.1.1</version>
        </dependency>

Note selenium 4 supports CDP up to v96 per https://github.com/SeleniumHQ/selenium/blob/201fad38296f9ea47ac1b1b59c160963dc7b2907/java/CHANGELOG

So I think the chromedriver and chrome version match. Does anyone know what could be causing the connection reset?

HeronAlgoSearch
  • 1,581
  • 2
  • 18
  • 35
  • I think that's not a error on your selenium, as the trace `java.net.SocketException: Connection reset` shows. It's a server problem like you can check [here](http://net-informations.com/java/err/reset.htm). – ojonasplima Jan 06 '22 at 15:04

2 Answers2

2

I've struggled with this for a bit and finally figured out what the problem was. When you see a "java.net.SocketException: Connection reset", it's (as far as I've seen) an issue specific to Chrome and ChromeDriver.

ChromeDriver uses a WebSocket to communicate with Chrome and when the quit() method is called and ChromeDriver tells Chrome to shut down ChromeDriver does not always close the browser process gracefully. Specifically, ChromeDriver does not disconnect/close the WebSocket before closing/quitting browser. This causes the error.

The (hopefully temporary) work-around is to add an argument to the ChromeOptions: --user-data-dir=/tmp/your_tmp_folder

In Java, you can do:

options.addArguments("--user-data-dir=" + System.getProperty("java.io.tmpdir"));

This will make ChromeDriver send a SIGTERM first to Chrome.

Source for this solution: https://bugs.chromium.org/p/chromedriver/issues/detail?id=3689&q=websocket&can=2

PVDM
  • 98
  • 7
  • When using options.addArguments("--user-data-dir=" + System.getProperty("java.io.tmpdir"));, I see Chrome Didn't Shut Down Correctly message. – NoNoNo Jun 14 '23 at 11:00
0

I think you should change driver.close to .quit

  • 1
    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). – Community Apr 28 '22 at 04:28