zl程序教程

您现在的位置是:首页 >  后端

当前栏目

从JDK1.8升级至JDK17后,selenium4.8.1报SocketException异常

异常 升级 JDK1.8
2023-09-27 14:21:31 时间
报错详情如下:
3月 01, 2023 5:19:09 上午 org.asynchttpclient.netty.handler.WebSocketHandler handleException
警告: onError
java.net.SocketException: Connection reset
	at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394)
	at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426)
	at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:259)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	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:833)

3月 01, 2023 5:19:09 上午 org.openqa.selenium.remote.http.WebSocket$Listener onError
警告: Connection reset
java.net.SocketException: Connection reset
	at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394)
	at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426)
	at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:259)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	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:833)

 查看官方说明 selenium4.8.1是基于JDK 1.8的...

Selenium 使用 WebSocket 协议来与浏览器进行通信,而不同版本的 JDK 对 WebSocket 的支持程度可能会有所不同。

在 JDK 1.8 中,WebSocket API 是一个可用的标准 API,并且已经被广泛使用和测试。因此,Selenium 在 JDK 1.8 中使用 WebSocket 协议可能会比在 JDK 17 中更加稳定。

在 JDK 17 中,WebSocket API 已经被重新设计和实现,并且仍然处于试验阶段。因此,如果您在 JDK 17 中使用 Selenium,可能会遇到一些与 WebSocket 相关的问题。

解决此问题的一种方法是在 JDK 17 中使用较新版本的 Selenium,该版本已经对 WebSocket API 进行了更新和优化。或者,您可以尝试在 JDK 17 中使用旧版本的 WebSocket API,以避免出现兼容性问题。