From 39f96a2320130f38b3e985235984c4ad72eb0e54 Mon Sep 17 00:00:00 2001 From: benjolsen Date: Fri, 5 Apr 2019 18:59:41 -0400 Subject: [PATCH] Update AsyncSocketServer.cs Added try-catch block around the socketsession constructors. Occasionally the underlying socket will have disappeared before the constructors try to access the socket causing an uncaught exception. This will catch these exceptions so the server will not crash. --- SocketEngine/AsyncSocketServer.cs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/SocketEngine/AsyncSocketServer.cs b/SocketEngine/AsyncSocketServer.cs index a87a10fd0..5a06211ca 100644 --- a/SocketEngine/AsyncSocketServer.cs +++ b/SocketEngine/AsyncSocketServer.cs @@ -102,14 +102,25 @@ private IAppSession ProcessNewClient(Socket client, SslProtocols security) } ISocketSession socketSession; + IAppSession session=null; + try + { + if (security == SslProtocols.None) + socketSession = new AsyncSocketSession(client, socketEventArgsProxy); + else + socketSession = new AsyncStreamSocketSession(client, security, socketEventArgsProxy); - if (security == SslProtocols.None) - socketSession = new AsyncSocketSession(client, socketEventArgsProxy); - else - socketSession = new AsyncStreamSocketSession(client, security, socketEventArgsProxy); - - var session = CreateSession(client, socketSession); - + session = CreateSession(client, socketSession); + } + catch + { + socketEventArgsProxy.Reset(); + this.m_ReadWritePool.Push(socketEventArgsProxy); + AppServer.AsyncRun(client.SafeClose); + return null; + } + + if (session == null) { socketEventArgsProxy.Reset();