Programing

원격 호스트가 기존 연결을 강제로 닫았습니다.

lottogame 2020. 7. 13. 08:08
반응형

원격 호스트가 기존 연결을 강제로 닫았습니다.


메시지와 함께 SocketException을 발생시키는 상용 응용 프로그램으로 작업하고 있습니다.

원격 호스트가 기존 연결을 강제로 닫았습니다.

이것은 클라이언트와 서버 간의 소켓 연결에서 발생합니다. 연결 상태가 양호하고 데이터 힙이 전송되고 있지만 연결이 끊어지지 않습니다.

아무도 전에 이것을 본 적이 있습니까? 원인은 무엇입니까? 몇 가지 원인을 추측 할 수 있지만이 코드에 더 많은 원인을 추가하여 원인을 파악할 수있는 방법이 있습니까?

모든 의견 / 아이디어를 환영합니다.

... 최신 ...

일부 .NET 추적에서 로깅이 있습니다.

System.Net.Sockets Verbose: 0 : [8188] Socket#30180123::Send() DateTime=2010-04-07T20:49:48.6317500Z

System.Net.Sockets Error: 0 : [8188] Exception in the Socket#30180123::Send - An existing connection was forcibly closed by the remote host DateTime=2010-04-07T20:49:48.6317500Z 

System.Net.Sockets Verbose: 0 : [8188] Exiting Socket#30180123::Send() -> 0#0

로깅의 다른 부분을 기반으로 '0 # 0'은 0 바이트 길이의 패킷이 전송되고 있음을 나타냅니다. 그러나 이것이 실제로 무엇을 의미합니까?

두 가지 가능성 중 하나가 발생하고 있으며 확실하지 않습니다.

1) 연결이 닫히고 있지만 데이터가 소켓에 기록되어 위의 예외가 발생합니다. 0 # 0은 소켓이 이미 닫혀있어 아무것도 전송되지 않았다는 의미입니다.

2) 연결이 여전히 열려 있고 0 바이트의 패킷이 전송되고 (즉, 코드에 버그가 있음) 0 # 0은 0 바이트의 패킷이 전송되고 있음을 의미합니다.

당신은 무엇을 생각합니까? 결론을 내릴 수는 없지만 다른 누군가가 이런 종류의 것을 보았을 것입니까?


이것은 일반적으로 원격 측이 연결을 닫았 음을 의미합니다 (일반적으로 TCP / IP RST패킷 을 전송하여 ). 타사 응용 프로그램을 사용하는 경우 가능한 원인은 다음과 같습니다.

  • 응용 프로그램에 잘못된 형식의 데이터를 보내고 있습니다 (HTTPS 요청을 HTTP 서버로 보내는 것을 포함 할 수 있음)
  • 클라이언트와 서버 간의 네트워크 링크가 어떤 이유로 중단됩니다
  • 타사 응용 프로그램에서 버그로 인해 버그가 발생했습니다.
  • 타사 응용 프로그램에서 시스템 리소스를 모두 사용했습니다

첫 번째 경우가 일어날 가능성이 높습니다.

당신은 해고 할 수 와이어 샤크를 문제를 좁힐 와이어에 무슨 일이 일어나고 정확하게 볼 수 있습니다.

더 구체적인 정보가 없으면 여기있는 사람이 실제로 많은 도움을 줄 것 같지 않습니다.


TLS 1.2를 사용하면이 오류가 해결되었습니다.
TLS 1.2를 사용하여 애플리케이션을 강제 실행할 수 있습니다 (서비스를 호출하기 전에 실행해야합니다).

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 

다른 해결책 :
TLS1.2를 사용하려면 로컬 컴퓨터 나 서버에서 강력한 암호화를 활성화하십시오 . 기본적으로 TLS1.0 만 사용되므로 비활성화됩니다.
강력한 암호화를 사용하려면 관리자 권한으로 PowerShell에서 다음 명령을 실행하십시오.

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord 

이러한 변경 사항을 적용하려면 컴퓨터를 재부팅해야합니다.


이것은 코드의 버그가 아닙니다. .Net의 소켓 구현에서 온 것입니다. 아래와 같이 오버로드 된 EndReceive 구현을 사용하면이 예외가 발생하지 않습니다.

    SocketError errorCode;
    int nBytesRec = socket.EndReceive(ar, out errorCode);
    if (errorCode != SocketError.Success)
    {
        nBytesRec = 0;
    }

이 일반적인 성가신 문제에 대한 간단한 해결책 :

" .context.cs"파일 ( "* .edmx"파일 아래에있는 " .context.tt"아래에 있음)로 이동하십시오.

그런 다음 생성자에 다음 행을 추가하십시오.

public DBEntities() 
        : base("name=DBEntities") 
    { 
        this.Configuration.ProxyCreationEnabled = false; // ADD THIS LINE !
    }

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


Had the same bug. Actually worked in case the traffic was sent using some proxy (fiddler in my case). Updated .NET framework from 4.5.2 to >=4.6 and now everything works fine. The actual request was:
new WebClient().DownloadData("URL");
The exception was:

SocketException: An existing connection was forcibly closed by the remote host


I've got this exception because of circular reference in entity.In entity that look like

public class Catalog
{
    public int Id { get; set; }
    public int ParentId { get; set; }
    public Catalog Parent { get; set; }
    public ICollection<Catalog> ChildCatalogs { get; set; }
}

I added [IgnoreDataMemberAttribute] to the Parent property. And that solved the problem.


If Running In A .Net 4.5.2 Service

For me the issue was compounded because the call was running in a .Net 4.5.2 service. I followed @willmaz suggestion but got a new error.

In running the service with logging turned on, I viewed the handshaking with the target site would initiate ok (and send the bearer token) but on the following step to process the Post call, it would seem to drop the auth token and the site would reply with Unauthorized.

It turned out that the service pool credentials did not have rights to change TLS (?) and when I put in my local admin account into the pool, it all worked.


I had the same issue and managed to resolve it eventually. In my case, the port that the client sends the request to did not have a SSL cert binding to it. So I fixed the issue by binding a SSL cert to the port on the server side. Once that was done, this exception went away.


This error occurred in my application with the CIP-protocol whenever I didn't Send or received data in less than 10s.

This was caused by the use of the forward open method. You can avoid this by working with an other method, or to install an update rate of less the 10s that maintain your forward-open-connection.


I got this exception when I was trying to read a row from the database that had a null in an enum column, it couldn't map the null into an enum value.

참고URL : https://stackoverflow.com/questions/2582036/an-existing-connection-was-forcibly-closed-by-the-remote-host

반응형