Programing

“소프트웨어가 연결 중단을 일으킨 이유 : 소켓 쓰기 오류”

lottogame 2020. 6. 15. 08:19
반응형

“소프트웨어가 연결 중단을 일으킨 이유 : 소켓 쓰기 오류”


이 스택 추적 스 니펫이 주어지면

원인 : java.net.SocketException : 소프트웨어로 인한 연결 중단 :
 java.net.SocketOutputStream.socketWrite0 (네이티브 메소드)에서 소켓 쓰기 오류

나는 다음과 같은 질문에 대답하려고 노력했다.

  1. 어떤 예외가이 예외를 던지고 있습니까? (JVM? / Tomcat? / 내 코드?)
  2. 이 예외가 발생하는 원인은 무엇입니까?

# 1에 관하여 :

Sun의 JVM 소스에는이 정확한 메시지가 포함되어 있지 않지만 소프트웨어에서 연결 중단을 일으킨 텍스트 : 소켓 쓰기 오류 는 다음과 같은 기본 구현에서 발생 했다고 생각합니다 SocketOutputStream.

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

# 2에 대하여

내 생각에 그것은 전체 응답을 받기 전에 클라이언트가 연결을 종료했을 때 발생합니다 (예 : 요청을 보냈지 만 전체 응답을 받기 전에 닫히거나 종료 / 오프라인 상태)

질문 :

  1. 위의 가정이 맞습니까 (# 1 및 # 2)?
  2. " 서버의 네트워크 오류로 인해 클라이언트에 쓸 수 없습니다"라는 상황에서이를 구별 할 수 있습니까 ? 또는 동일한 오류 메시지가 표시됩니까?
  3. 그리고 가장 중요한 : 위의 내용을 명시한 공식 문서 (예 : Sun)가 있습니까?

이 스택 추적이 소켓 클라이언트의 "결함"이라는 증거가 필요하며 서버가이를 피하기 위해 할 수있는 일은 없습니다. (예외를 잡거나 Sun JVM SocketOutputStream 이외의 것을 사용하는 것을 제외하고는 클라이언트가 종료되었다는 사실을 실제로 피하지는 않습니다)


이 오류는 로컬 네트워크 시스템이 연결을 중단 할 때 (예 : 데이터 재전송이 실패한 후 WinSock이 설정된 연결을 닫을 때 (수신자가 데이터 스트림 소켓에서 전송 된 데이터를 승인하지 않음)) 발생할 수 있습니다.

참조 이 MSDN 문서를 . '소프트웨어로 인한 연결 중단'에 대한 일부 정보 도 참조하십시오 .


java.net.SocketException만들거나 액세스 할 경우에 에러가 발생했을 경우에 슬로우되는 소켓을 (예 : TCP ). 이는 일반적으로 서버가 연결을 종료하지 않은 경우 (올바로 닫지 않은 상태) 발생할 수 있으므로 전체 응답을 얻기 전에 발생할 수 있습니다. 대부분의 경우 시간 초과 문제 (예 : 응답 시간이 너무 오래 걸리거나 서버에 요청이 오버로드 됨) 또는 클라이언트가 SYN을 보냈지 만 ACK를받지 못했습니다 (연결 종료 확인) . 시간 초과 문제의 경우 시간 초과 값을 늘릴 수 있습니다.

소켓 예외는 일반적으로 문제에 대한 지정된 세부 메시지와 함께 제공됩니다.

자세한 메시지 예 :

  • 소프트웨어에서 연결 중단이 발생했습니다 : recv 실패.

    이 오류는 메시지 전송 시도를 나타내며 서버에서 연결을 중단했습니다. 데이터베이스에 연결하는 동안이 문제가 발생하면 호환되지 않는 Connector / J JDBC 드라이버 사용과 관련이있을 수 있습니다 .

    가능한 해결책 : CLASSPATH에 적절한 라이브러리 / 드라이버가 있는지 확인하십시오.

  • 소프트웨어에서 연결 중단이 발생했습니다 : 연결.

    리모컨 연결에 문제가있을 때 발생할 수 있습니다. 예를 들어 바이러스 검사 프로그램이 원격 메일 요청을 거부하기 때문 입니다.

    가능한 해결책 : 바이러스 검색 서비스가 나가는 연결 요청에 대한 포트를 차단하고 있는지 확인하십시오.

  • 소프트웨어에서 연결 중단이 발생했습니다 : 소켓 쓰기 오류.

    가능한 해결책 : 스트림에 올바른 길이의 바이트를 쓰고 있는지 확인하십시오. 전송중인 내용을 다시 확인하십시오. 스레드를 참조하십시오 .

  • 피어에 의한 연결 재설정 : 소켓 쓰기 오류 / 피어에 의한 연결 중단 : 소켓 쓰기 오류

    서버 쪽에서 연결 유지 연결 시간이 초과되었는지 응용 프로그램에서 확인하지 않았습니다.

    가능한 해결책 : 연결에서 읽기 전에 HttpClient가 널이 아닌지 확인하십시오. E13222_01

  • 피어에 의한 연결 재설정

    피어 (서버)가 연결을 종료했습니다.

  • 연결 재설정.

    요청에 의한 요청으로 인해 클라이언트가 연결을 종료했거나 연결이 서버 쪽에서 닫혔습니다.

    참조 : 내 java.net.SocketException의 원인을 무엇 : 연결 재설정?


워크 스테이션 / 노트북의 회사 방화벽이 방해를 받으면 연결이 끊어집니다.

예. 같은 컴퓨터에 서버 프로세스와 클라이언트 프로세스가 있습니다. 서버가 모든 인터페이스 (0.0.0.0)에서 수신 대기 중이며 클라이언트가 공용 / 홈 인터페이스 (루프백 인터페이스 127.0.0.1이 아님)에 대한 연결을 시도합니다.

기기의 네트워크 연결이 끊긴 경우 (예 : wifi가 꺼진 경우) 연결이 형성됩니다. 기기가 회사 네트워크 (직접 또는 VPN)에 연결된 경우 연결이 형성됩니다.

그러나 기기가 공용 ​​Wi-Fi (또는 홈 네트워크)에 연결되어 있으면 방화벽이 작동하여 연결이 끊어집니다. 이 상황에서 클라이언트를 루프백 인터페이스에 연결하면 홈 / 공용 인터페이스가 아니라 제대로 작동합니다.

도움이 되었기를 바랍니다.


To prove which component fails I would monitor the TCP/IP communication using wireshark and look who is actaully closing the port, also timeouts could be relevant.


Have you checked the Tomcat source code and the JVM source ? 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. The above looks very like it's client-driven.


For anyone using simple Client Server programms and getting this error, it is a problem of unclosed (or closed to early) Input or Output Streams.


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.


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.

On SoapUI go to:

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.


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. The source of the error was that I had initially opened the database with SQuirreL to check manually for integrity. I did use the flag to enable multiple connections to the same DB (i.e. AUTO_SERVER=TRUE), so there was no problem connecting to the DB from java.

The error appeared when, after a while --it is a long java process-- I decided to close SQuirreL to free resources. It appears as if SQuirreL were the one "owning" the DB server instance and that it was shut down with the SQuirreL connection.

Restarting the Java application did not yield the error again.

config

  • Windows 7
  • Eclipse Kepler
  • SQuirreL 3.6
  • org.h2.Driver ver 1.4.192

My server was throwing this exception in the pass 2 days and I solved it by moving the disconnecting function with:

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

To the end of the listing thread. if it will helped anyone.


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.


ssl client side will throw such exception in below situation(I had tested), :

server is asked to authenticate client certificate, but the client provide a certificate which Extended Key Usage donot support client auth.


I was facing the same problem with wireMock while mocking the rest API calls. 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);

참고URL : https://stackoverflow.com/questions/2126607/official-reasons-for-software-caused-connection-abort-socket-write-error

반응형