From 6d25f84f331e40f32af2c1422a95bbe863c95409 Mon Sep 17 00:00:00 2001 From: Vasyl Horbachenko Date: Fri, 23 Aug 2019 07:42:33 +0300 Subject: [PATCH] Fixed NullReference if socket was closed too fast. --- WatsonWebserver/WatsonWebserver.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/WatsonWebserver/WatsonWebserver.cs b/WatsonWebserver/WatsonWebserver.cs index f56a356a..3e3f1dc6 100644 --- a/WatsonWebserver/WatsonWebserver.cs +++ b/WatsonWebserver/WatsonWebserver.cs @@ -264,15 +264,14 @@ private void AcceptConnections(CancellationToken token) if (token.IsCancellationRequested) throw new OperationCanceledException(); var context = c as HttpListenerContext; - - Events.ConnectionReceived( - context.Request.RemoteEndPoint.Address.ToString(), - context.Request.RemoteEndPoint.Port); - HttpRequest req = null; - + try { + Events.ConnectionReceived( + context.Request.RemoteEndPoint.Address.ToString(), + context.Request.RemoteEndPoint.Port); + // Populate HTTP request object req = new HttpRequest(context, ReadInputStream); if (req == null)