简体   繁体   English

“软件导致连接中止:套接字写入错误”的官方原因

[英]Official reasons for "Software caused connection abort: socket write error"

Given this stack trace snippet鉴于此堆栈跟踪片段

Caused by: java.net.SocketException: Software caused connection abort: socket write error引起:java.net.SocketException:软件导致连接中止:套接字写入错误
at java.net.SocketOutputStream.socketWrite0(Native Method)在 java.net.SocketOutputStream.socketWrite0(本机方法)

I tried to answer the following questions:我试图回答以下问题:

  1. What code is throwing this exception?什么代码抛出这个异常? (JVM?/Tomcat?/My code?) (JVM?/Tomcat?/我的代码?)
  2. What causes this exception to be thrown?是什么导致抛出这个异常?

Regarding #1:关于#1:

Sun's JVM source doesn't contain this exact message, but I think the text Software caused connection abort: socket write error is from the native implementation of SocketOutputStream : Sun 的 JVM 源不包含此确切消息,但我认为文本软件导致连接中止:套接字写入错误来自SocketOutputStream的本机实现:

private native void socketWrite0(FileDescriptor fd, byte[] b, int off,
                 int len) throws IOException;

Regarding #2关于#2

My guess is that it is caused when the client has terminated the connection, before getting the full response (eg sent a request, but before getting the full response, it got closed / terminated / offline)我的猜测是它是在客户端终止连接时引起的,在获得完整响应之前(例如发送了一个请求,但在获得完整响应之前,它被关闭/终止/离线)

Questions:问题:

  1. Are the above assumptions correct (#1 and #2)?上述假设是否正确(#1 和 #2)?
  2. Can this be diffrentiated from the situation: "could not write to the client, due to a network error on the server side"?这可以与以下情况区别开来:“由于服务器端的网络错误,无法写入客户端”? or would that render the same error message?还是会呈现相同的错误消息?
  3. And most important: Is there an official document (eg from Sun) stating the above?最重要的是否有官方文件(例如来自 Sun)说明上述内容?

I need to have a proof that this stack trace is the socket client's "fault", and there is nothing that the server could have done to avoid it.我需要证明这个堆栈跟踪是套接字客户端的“错误”,并且服务器无法避免它。 (except catching the exception, or using a non Sun JVM SocketOutputStream, though both don't really avoid the fact the client has terminated) (除了捕获异常,或使用非 Sun JVM SocketOutputStream,尽管两者都没有真正避免客户端已终止的事实)

This error can occur when the local network system aborts a connection, such as when WinSock closes an established connection after data retransmission fails (receiver never acknowledges data sent on a datastream socket).当本地网络系统中止连接时,例如当 WinSock 在数据重新传输失败后关闭已建立的连接(接收器从不确认数据流套接字上发送的数据)时,可能会发生此错误。

See this MSDN article .请参阅此 MSDN 文章 See also Some information about 'Software caused connection abort' .另请参阅有关“软件导致连接中止”的一些信息

The java.net.SocketException is thrown when there is an error creating or accessing a socket (such as TCP ). java.net.SocketException在创建或访问套接字(例如TCP )时出现错误时抛出。 This usually can be caused when the server has terminated the connection (without properly closing it), so before getting the full response.这通常是在服务器终止连接(没有正确关闭它)时引起的,因此在获得完整响应之前。 In most cases this can be caused either by the timeout issue (eg the response takes too much time or server is overloaded with the requests), or the client sent the SYN, but it didn't receive ACK (acknowledgment of the connection termination).在大多数情况下,这可能是由超时问题引起的(例如,响应花费了太多时间或服务器因请求而过载),或者客户端发送了 SYN,但它没有收到 ACK(连接终止的确认) . For timeout issues, you can consider increasing the timeout value.对于超时问题,可以考虑增加超时值。

The Socket Exception usually comes with the specified detail message about the issue.套接字异常通常带有有关该问题的指定详细消息。

Example of detailed messages:详细消息示例:

  • Software caused connection abort: recv failed.软件导致连接中止:接收失败。

    The error indicates an attempt to send the message and the connection has been aborted by your server.该错误表示尝试发送消息并且连接已被您的服务器中止。 If this happened while connecting to the database, this can be related to using not compatible Connector/J JDBC driver .如果在连接到数据库时发生这种情况,这可能与使用不兼容的 Connector/J JDBC 驱动程序有关

    Possible solution: Make sure you've proper libraries/drivers in your CLASSPATH.可能的解决方案:确保您的 CLASSPATH 中有正确的库/驱动程序。

  • Software caused connection abort: connect.软件导致连接中止:connect。

    This can happen when there is a problem to connect to the remote.当连接到遥控器出现问题时,可能会发生这种情况。 For example due to virus-checker rejecting the remote mail requests .例如, 由于病毒检查器拒绝远程邮件请求

    Possible solution: Check Virus scan service whether it's blocking the port for the outgoing requests for connections.可能的解决方案:检查病毒扫描服务是否阻塞了用于发出连接请求的端口。

  • Software caused connection abort: socket write error.软件导致连接中止:套接字写入错误。

    Possible solution: Make sure you're writing the correct length of bytes to the stream.可能的解决方案:确保将正确长度的字节写入流。 So double check what you're sending.因此,请仔细检查您发送的内容。 See this thread .看到这个线程

  • Connection reset by peer: socket write error / Connection aborted by peer: socket write error对等方重置连接:套接字写错误/对等方中止连接:套接字写错误

    The application did not check whether keep-alive connection had been timed out on the server side.应用程序没有检查服务器端的保持连接是否超时。

    Possible solution: Ensure that the HttpClient is non-null before reading from the connection.可能的解决方案:在从连接读取之前确保 HttpClient 为非空。 E13222_01 E13222_01

  • Connection reset by peer.对等方重置连接。

    The connection has been terminated by the peer (server).连接已被对等方(服务器)终止。

  • Connection reset.连接重置。

    The connection has been either terminated by the client or closed by the server end of the connection due to request with the request.连接要么被客户端终止,要么被连接的服务器端关闭,因为请求带有请求。

    See: What's causing my java.net.SocketException: Connection reset?请参阅:是什么导致了我的 java.net.SocketException:连接重置?

I have seen this most often when a corporate firewall on a workstation/laptop gets in the way, it kills the connection.当工作站/笔记本电脑上的企业防火墙妨碍连接时,我最常看到这种情况。

eg.例如。 I have a server process and a client process on the same machine.我在同一台机器上有一个服务器进程和一个客户端进程。 The server is listening on all interfaces (0.0.0.0) and the client attempts a connection to the public/home interface (note not the loopback interface 127.0.0.1).服务器正在侦听所有接口 (0.0.0.0),客户端尝试连接到公共/本地接口(注意不是环回接口 127.0.0.1)。

If the machine is has its network disconnected (eg wifi turned off) then the connection is formed.如果机器的网络断开(例如wifi关闭),则连接形成。 If the machine is connected to the corporate network (directly or vpn) then the connection is formed.如果机器连接到公司网络(直接或 vpn),则连接形成。

However, if the machine is connected to a public wifi (or home network) then the firewall kicks in an kills the connection.但是,如果机器连接到公共 wifi(或家庭网络),则防火墙会启动并终止连接。 In this situation connecting the client to the loopback interface works fine, just not to the home/public interface.在这种情况下,将客户端连接到环回接口工作正常,只是不能连接到家庭/公共接口。

Hope this helps.希望这可以帮助。

为了证明哪个组件出现故障,我将使用wireshark监视TCP/IP 通信并查看谁实际关闭了端口,超时也可能相关。

对于使用简单的客户端服务器程序并收到此错误的任何人来说,这是未关闭(或关闭到早期)输入或输出流的问题。

Have you checked the Tomcat source code and the JVM source ?您是否检查过 Tomcat 源代码JVM 源代码? That may give you more help.那可能会给你更多的帮助。

I think your general thinking is good.我认为你的总体思路很好。 I would expect a ConnectException in the scenario that you couldn't connect.我希望在您无法连接的情况下出现ConnectException The above looks very like it's client-driven.上面看起来很像它是客户端驱动的。

I was facing the same issue.我面临着同样的问题。
Commonly This kind of error occurs due to client has closed its connection and server still trying to write on that client.通常发生这种错误是由于客户端已关闭其连接而服务器仍在尝试在该客户端上写入。
So make sure that your client has its connection open until server done with its outputstream.因此,请确保您的客户端打开其连接,直到服务器完成其输出流。
And one more thing, Don`t forgot to close input and output stream.还有一件事,不要忘记关闭输入和输出流。

Hope this helps.希望这可以帮助。
And if still facing issue than brief your problem here in details.如果仍然面临问题,请在此处详细介绍您的问题。

Had an SSLPoke.bat (SSL troubleshooting script) window script that was getting this error despite importing the correct certificates into the cacerts trustore.有一个 SSLPoke.bat(SSL 故障排除脚本)窗口脚本,尽管将正确的证书导入 cacerts trustore,但仍出现此错误。

C:\Java\jdk1.8.0_111\jre\lib\security>SSLPoke.bat

C:\Java\jdk1.8.0_111\jre\lib\security>"C:\jdk1.8.0_101\jre\bin\java" 
     `SSLPoke  tfs.corp.****.com  443`

java.net.SocketException: Software caused connection abort: recv failed
    `at java.net.SocketInputStream.socketRead0(Native Method)`
    `at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)`
    `at java.net.SocketInputStream.read(SocketInputStream.java:170)`
    `at java.net.SocketInputStream.read(SocketInputStream.java:141)`
    `at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)`
    `at sun.security.ssl.InputRecord.read(InputRecord.java:503)`
    `at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)`
    `at sun.security.ssl.SSLSocketImpl.performInitialHandshake
       (SSLSocketImpl.java:1375)`
    `at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747)`
    `at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)`
    `at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:138)`
    `at SSLPoke.main(SSLPoke.java:28)`

I then checked some old notes about some network changes at my job.然后我检查了一些关于我工作中一些网络变化的旧笔记。 We would need in some cases to add the JVM parameter -Djava.net.preferIPv4Stack=true to make connections to certain machines in our network to avoid this error.在某些情况下,我们需要添加 JVM 参数-Djava.net.preferIPv4Stack=true to make connections to certain machines我们网络中的-Djava.net.preferIPv4Stack=true to make connections to certain machines以避免此错误。

C:\Java\jdk1.8.0_111\jre\lib\security>"C:\Java\jdk1.8.0_111\bin\java"  
    **-Djava.net.preferIPv4Stack=true**  SSLPoke tfs.corp.****.com 443

Successfully connected连接成功

The code for SSLPoke can be downloaded from here: https://gist.github.com/4ndrej/4547029 SSLPoke 的代码可以从这里下载: https ://gist.github.com/4ndrej/4547029

This error happened to me while testing my soap service with SoapUI client, basically I was trying to get a very big message (>500kb) and SoapUI closed the connection by timeout.这个错误发生在我用 SoapUI 客户端测试我的肥皂服务时,基本上我试图获得一个非常大的消息(> 500kb)并且 SoapUI 超时关闭了连接。

On SoapUI go to:在 SoapUI 上转到:

File-->Preferences--Socket Timeout(ms)文件-->首选项--套接字超时(毫秒)

...and put a large value, such as 180000 (3 minutes), this won't be the perfect fix for your issue because the file is in fact to large, but at least you will have a response. ...并输入一个较大的值,例如 180000(3 分钟),这不是解决您问题的完美方法,因为该文件实际上太大了,但至少您会有响应。

Closed connection in another client在另一个客户端关闭连接

In my case, the error was:就我而言,错误是:

java.net.SocketException: Software caused connection abort: recv failed

It was received in eclipse while debugging a java application accessing a H2 database.它是在 eclipse 中调试访问 H2 数据库的 Java 应用程序时收到的。 The source of the error was that I had initially opened the database with SQuirreL to check manually for integrity.错误的根源是我最初使用 SQuirreL 打开数据库以手动检查完整性。 I did use the flag to enable multiple connections to the same DB (ie AUTO_SERVER=TRUE ), so there was no problem connecting to the DB from java.我确实使用该标志启用到同一个数据库的多个连接(即AUTO_SERVER=TRUE ),因此从 java 连接到数据库没有问题。

The error appeared when, after a while --it is a long java process-- I decided to close SQuirreL to free resources.过了一会儿——这是一个很长的Java进程——我决定关闭SQuirreL以释放资源时出现错误。 It appears as if SQuirreL were the one "owning" the DB server instance and that it was shut down with the SQuirreL connection.看起来好像 SQuirreL 是“拥有”数据库服务器实例的人,并且它已通过 SQuirreL 连接关闭。

Restarting the Java application did not yield the error again.重新启动 Java 应用程序没有再次产生错误。

config配置

  • Windows 7 Windows 7的
  • Eclipse Kepler日食开普勒
  • SQuirreL 3.6松鼠 3.6
  • org.h2.Driver ver 1.4.192 org.h2.Driver 版本 1.4.192

In the situation explained below, client side will throw such an exception:在下面解释的情况下,客户端会抛出这样的异常:

The server is asked to authenticate client certificate, but the client provides a certificate which Extended Key Usage doesn't support client auth, so the server doesn't accept the client's certificate, and then it closes the connection.服务器被要求对客户端证书进行身份验证,但客户端提供了扩展密钥用法不支持客户端身份验证的证书,因此服务器不接受客户端的证书,然后关闭连接。

My server was throwing this exception in the pass 2 days and I solved it by moving the disconnecting function with:我的服务器在过去 2 天内抛出了这个异常,我通过移动断开连接功能解决了这个问题:

outputStream.close();
inputStream.close();
Client.close();

To the end of the listing thread.到列表线程的末尾。 if it will helped anyone.如果它会帮助任何人。

Given this stack trace snippet给定此堆栈跟踪代码段

Caused by: java.net.SocketException: Software caused connection abort: socket write error引起原因:java.net.SocketException:软件导致连接中止:套接字写入错误
at java.net.SocketOutputStream.socketWrite0(Native Method)在java.net.SocketOutputStream.socketWrite0(本机方法)

I tried to answer the following questions:我试图回答以下问题:

  1. What code is throwing this exception?哪些代码引发此异常? (JVM?/Tomcat?/My code?) (JVM?/ Tomcat?/我的代码?)
  2. What causes this exception to be thrown?是什么导致引发此异常?

Regarding #1:关于#1:

Sun's JVM source doesn't contain this exact message, but I think the text Software caused connection abort: socket write error is from the native implementation of SocketOutputStream : Sun的JVM源不包含此确切消息,但我认为文本软件导致连接中止:套接字写入错误来自SocketOutputStream的本机实现:

private native void socketWrite0(FileDescriptor fd, byte[] b, int off,
                 int len) throws IOException;

Regarding #2关于#2

My guess is that it is caused when the client has terminated the connection, before getting the full response (eg sent a request, but before getting the full response, it got closed / terminated / offline)我的猜测是,这是由于客户端在获得完整响应之前(例如,发送了一个请求,但是在获得完整响应之前,它已关闭/终止/脱机)终止了连接。

Questions:问题:

  1. Are the above assumptions correct (#1 and #2)?以上假设是否正确(#1和#2)?
  2. Can this be diffrentiated from the situation: "could not write to the client, due to a network error on the server side"?是否可以与以下情况区别开来:“由于服务器端发生网络错误而无法写入客户端”? or would that render the same error message?还是会呈现相同的错误消息?
  3. And most important: Is there an official document (eg from Sun) stating the above?最重要的是否有正式文件(例如来自Sun的文件)说明上述内容?

I need to have a proof that this stack trace is the socket client's "fault", and there is nothing that the server could have done to avoid it.我需要证明此堆栈跟踪是套接字客户端的“故障”,并且服务器无法做任何事情来避免它。 (except catching the exception, or using a non Sun JVM SocketOutputStream, though both don't really avoid the fact the client has terminated) (捕获异常或使用非Sun JVM SocketOutputStream除外,尽管两者都不能真正避免客户端已终止的事实)

In my case, I developped the client and the server side, and I have the exception :就我而言,我开发了客户端和服务器端,但有一个例外:

Cause : error marshalling arguments;原因:错误编组参数; nested exception is: java.net.SocketException: Software caused connection abort: socket write error嵌套异常为:java.net.SocketException:软件导致连接中止:套接字写入错误

when classes in client and server are different.当客户端和服务器中的类不同时。 I don't download server's classes (Interfaces) on the client, I juste add same files in the project.我不在客户端下载服务器的类(接口),我只是在项目中添加相同的文件。 But the path must be exactly the same.但路径必须完全相同。 For example, on the server project I have java\\rmi\\services packages with some serviceInterface and implementations, I have to create the same package on the client project.例如,在服务器项目上,我有带有一些 serviceInterface 和实现的 java\\rmi\\services 包,我必须在客户端项目上创建相同的包。 If I change it by java/rmi/server/services for example, I get the above exception.例如,如果我通过 java/rmi/server/services 更改它,则会出现上述异常。 Same exception if the interface version is different between client and server (even with an empty row added inadvertently ... I think rmi makes a sort of hash of classes to check version ... I don't know... If it could help ...如果客户端和服务器之间的接口版本不同,则相同的异常(即使无意中添加了一个空行......我认为 rmi 制作了一种类的哈希来检查版本......我不知道......如果可以的话帮助 ...

I was facing the same problem with wireMock while mocking the rest API calls.我在模拟其余 API 调用时遇到了与 wireMock 相同的问题。 Earlier I was defining the server like this:早些时候我是这样定义服务器的:

WireMockServer wireMockServer = null;

But it should be defined like as shown below:但它应该定义如下:

@Rule 
public WireMockRule wireMockRule = new WireMockRule(8089);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 软件导致连接中止:套接字写入错误 - Software caused connection abort: socket write error jvisualvm:软件导致连接中止:套接字写入错误 - jvisualvm: Software caused connection abort: socket write error 软件导致连接异常终止:写入DataOutputStream时套接字写入错误 - Software caused connection abort: socket write error while writing to DataOutputStream java.net.SocketException:软件导致连接中止:重新提交请求时套接字写入错误 - java.net.SocketException: Software caused connection abort: socket write error when resubmitting the request javax.servlet.jsp.JspException:无法插入页面…软件导致连接中止:套接字写入错误 - javax.servlet.jsp.JspException: Can't insert page … Software caused connection abort: socket write error 通过串行端口java.net.SocketException的通信:软件导致连接中止:套接字写入错误 - Communication through serial port, java.net.SocketException: Software caused connection abort: socket write error 在FTP中存储ObjectOutputStream导致java.net.SocketException:软件导致连接中止:套接字写入错误 - Store ObjectOutputStream in FTP causes java.net.SocketException: Software caused connection abort: socket write error Maven Web项目在eclipse(tomcat 7)中运行错误:错误:无法调用Tomcat管理器:软件导致连接中止:套接字写入错误 - The maven web project runs error in eclipse(tomcat 7):error:Cannot invoke Tomcat manager: Software caused connection abort: socket write error 软件导致连接中止:即使从最近的列表中清除了该应用程序,套接字写入错误(它在与服务不同的线程中运行) - Software caused connection abort: socket write error on clearing the app from recent list even (it running in a different thread from a service) Java错误 - 软件导致连接中止:recv失败 - Java error - Software caused connection abort: recv failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM