SuperSocket icon indicating copy to clipboard operation
SuperSocket copied to clipboard

SocketException: The socket is not connected

Open jackcaicn opened this issue 8 years ago • 10 comments

Mono上运行,比较频繁的出现这个错

System.Net.Sockets.SocketException: The socket is not connected
  at System.Net.Sockets.Socket.get_RemoteEndPoint () [0x00000] in <filename unkn  n>:0
  at SuperSocket.SocketEngine.SocketSession..ctor (System.Net.Sockets.Socket cli  t) [0x00000] in <filename unknown>:0
  at SuperSocket.SocketEngine.AsyncSocketSession..ctor (System.Net.Sockets.Socket client, SuperSocket.SocketEngine.AsyncSocket.SocketAsyncEventArgsProxy socketA  ncProxy, Boolean isReset) [0x00000] in <filename unknown>:0
  at SuperSocket.SocketEngine.AsyncSocketSession..ctor (System.Net.Sockets.Socket client, SuperSocket.SocketEngine.AsyncSocket.SocketAsyncEventArgsProxy socketA  ncProxy) [0x00000] in <filename unknown>:0
  at SuperSocket.SocketEngine.AsyncSocketServer.ProcessNewClient (System.Net.Soc  ts.Socket client, SslProtocols security) [0x00000] in <filename unknown>:0
  at SuperSocket.SocketEngine.AsyncSocketServer.OnNewClientAccepted (ISocketListener listener, System.Net.Sockets.Socket client, System.Object state) [0x00000]    <filename unknown>:0
  at SuperSocket.SocketEngine.SocketListenerBase.OnNewClientAccepted (System.Net  ockets.Socket socket, System.Object state) [0x00000] in <filename unknown>:0
  at SuperSocket.SocketEngine.TcpAsyncSocketListener.ProcessAccept (System.Net.S  kets.SocketAsyncEventArgs e) [0x00000] in <filename unknown>:0
  at SuperSocket.SocketEngine.TcpAsyncSocketListener.acceptEventArg_Completed (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in <fi  name unknown>:0
  at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.Soc  tAsyncEventArgs e) [0x00000] in <filename unknown>:0
  at System.Net.Sockets.SocketAsyncEventArgs.AcceptCallback (IAsyncResult ares)   x00000] in <filename unknown>:0
  at System.Net.Sockets.SocketAsyncEventArgs.DispatcherCB (IAsyncResult ares) [0x00000] in <filename unknown>:0

jackcaicn avatar Jul 08 '16 03:07 jackcaicn

从异常堆栈来看,是连接建立之后马上断开了?

kerryjiang avatar Jul 08 '16 15:07 kerryjiang

出错的时候并没有任何连接,mono运行时比较频繁出现

northroom avatar Dec 19 '16 09:12 northroom

啥版本?

kerryjiang avatar Dec 19 '16 19:12 kerryjiang

SuperSocket 1.6.6.1, mono 4.6.2.7,Ubuntu 16.04.1 LTS 64 位,腾讯云,长时间运行大概5-20小时,会出现这个错误,此时并没有客户端连接 堆栈如下:

System.Net.Sockets.SocketException (0x80004005): The socket is not connected
at System.Net.Sockets.Socket.get_RemoteEndPoint () [0x0003e] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at SuperSocket.SocketEngine.SocketSession..ctor (System.Net.Sockets.Socket client) [0x0004a] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.AsyncSocketSession..ctor (System.Net.Sockets.Socket client, SuperSocket.SocketEngine.AsyncSocket.SocketAsyncEventArgsProxy socketAsyncProxy, System.Boolean isReset) [0x00000] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.AsyncSocketSession..ctor (System.Net.Sockets.Socket client, SuperSocket.SocketEngine.AsyncSocket.SocketAsyncEventArgsProxy socketAsyncProxy) [0x00000] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.AsyncSocketServer.ProcessNewClient (System.Net.Sockets.Socket client, System.Security.Authentication.SslProtocols security) [0x0008f] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.AsyncSocketServer.OnNewClientAccepted (SuperSocket.SocketEngine.ISocketListener listener, System.Net.Sockets.Socket client, System.Object state) [0x0001d] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.SocketListenerBase.OnNewClientAccepted (System.Net.Sockets.Socket socket, System.Object state) [0x00010] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.TcpAsyncSocketListener.ProcessAccept (System.Net.Sockets.SocketAsyncEventArgs e) [0x0009d] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.TcpAsyncSocketListener.acceptEventArg_Completed (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00001] in <dd5d702ee1144c5a8387640fb645f5b6>:0 
  at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) [0x00014] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Sockets.SocketAsyncEventArgs.Complete () [0x00000] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Sockets.Socket.<AcceptAsyncCallback>m__0 (System.IAsyncResult ares) [0x000a0] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Sockets.SocketAsyncResult+<Complete>c__AnonStorey0.<>m__0 (System.Object _) [0x00000] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00019] in <8f2c484307284b51944a1a13a14c0266>:0
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in <8f2c484307284b51944a1a13a14c0266>:0
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0

northroom avatar Dec 20 '16 01:12 northroom

This just happened to me as well. Any way we can catch the exception so it does not crash the whole server? Thanks!

SuperSocket (WebSocket): 1.6.6.1 Mono: 5.18.0.225 Ubuntu 18.04.1 LTS

Unhandled Exception:
System.Net.Sockets.SocketException (0x80004005): The socket is not connected
  at System.Net.Sockets.Socket.get_RemoteEndPoint () [0x00035] in <eeec8e88b1fc462e84ade7bf334d0c97>:0
  at SuperSocket.SocketEngine.SocketSession..ctor (System.Net.Sockets.Socket client) [0x0004a] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.AsyncSocketSession..ctor (System.Net.Sockets.Socket client, SuperSocket.SocketEngine.AsyncSocket.SocketAsyncEventArgsProxy socketAsyncProxy, System.Boolean isReset) [0x00000] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.AsyncSocketSession..ctor (System.Net.Sockets.Socket client, SuperSocket.SocketEngine.AsyncSocket.SocketAsyncEventArgsProxy socketAsyncProxy) [0x00000] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.AsyncSocketServer.ProcessNewClient (System.Net.Sockets.Socket client, System.Security.Authentication.SslProtocols security) [0x0008f] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.AsyncSocketServer.OnNewClientAccepted (SuperSocket.SocketEngine.ISocketListener listener, System.Net.Sockets.Socket client, System.Object state) [0x0001d] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.SocketListenerBase.OnNewClientAccepted (System.Net.Sockets.Socket socket, System.Object state) [0x00010] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.TcpAsyncSocketListener.ProcessAccept (System.Net.Sockets.SocketAsyncEventArgs e) [0x0009d] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at SuperSocket.SocketEngine.TcpAsyncSocketListener.acceptEventArg_Completed (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00001] in <dd5d702ee1144c5a8387640fb645f5b6>:0
  at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) [0x0000e] in <eeec8e88b1fc462e84ade7bf334d0c97>:0
  at System.Net.Sockets.SocketAsyncEventArgs.Complete () [0x00009] in <eeec8e88b1fc462e84ade7bf334d0c97>:0
  at System.Net.Sockets.Socket+<>c.<.cctor>b__313_0 (System.IAsyncResult ares) [0x00092] in <eeec8e88b1fc462e84ade7bf334d0c97>:0
  at System.Net.Sockets.SocketAsyncResult+<>c.<Complete>b__27_0 (System.Object state) [0x0000b] in <eeec8e88b1fc462e84ade7bf334d0c97>:0
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00008] in <7b0d87324cab49bf96eac679025e77d1>:0
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <7b0d87324cab49bf96eac679025e77d1>:0
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <7b0d87324cab49bf96eac679025e77d1>:0

benjolsen avatar Jan 21 '19 15:01 benjolsen

I am also reporting above issue happening, and also wondering on how to to catch exception so that it wouldn't crash whole service?

System Desc: SuperSocket: 1.6.6.1 Mono: 5.18.0.240 Ubuntu: 18.04

kha1ne avatar Feb 25 '19 09:02 kha1ne

I have an app with a similar behaviour under Mono, it's a "System.Net.Sockets.SocketException (0x80004005): The socket is not connected" error. This is an inner exception which is caught just fine in Windows when I test, but for some reason under Mono it crashes the whole server. Any workaround?

adrenaline96 avatar Apr 20 '19 07:04 adrenaline96

I have an app with a similar behaviour under Mono, it's a "System.Net.Sockets.SocketException (0x80004005): The socket is not connected" error. This is an inner exception which is caught just fine in Windows when I test, but for some reason under Mono it crashes the whole server. Any workaround?

We got the same exception. Have u worked out this issue?

cash2910 avatar Jan 05 '23 07:01 cash2910

大佬这个问题后面是怎么解决的?

cash2910 avatar Jan 05 '23 07:01 cash2910

This issue is caused by custom TCP which sends RST frame as a finished frame. It will crash the whole server within a mono env. To avoid this is to modify the code by adding a try statement.

protected override void OnNewClientAccepted(ISocketListener listener, Socket client, object state)
 {
            if (IsStopped)
                return;
            Console.WriteLine("start to accept logic");
            try
            {
                ProcessNewClient(client, listener.Info.Security);
            }
            catch (SocketExceptione)
            {
                Console.WriteLine(e);
                throw;
            }
 }

SuperSocket-1.6\SocketEngine\AsyncSocketServer.cs

cash2910 avatar Jan 09 '23 07:01 cash2910