From ca2a4716911605068430da015e47638985aabae1 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Tue, 25 Oct 2016 17:38:11 -0700 Subject: [PATCH] Fixing NRE when a client closes connection --- samples/SocketsSample/EndPoints/RpcEndpoint.cs | 11 +++++------ samples/SocketsSample/LineInvocationAdapter.cs | 5 +++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/samples/SocketsSample/EndPoints/RpcEndpoint.cs b/samples/SocketsSample/EndPoints/RpcEndpoint.cs index 29f64884b9..216b310ed3 100644 --- a/samples/SocketsSample/EndPoints/RpcEndpoint.cs +++ b/samples/SocketsSample/EndPoints/RpcEndpoint.cs @@ -14,7 +14,6 @@ using SocketsSample.Protobuf; namespace SocketsSample { - // This end point implementation is used for framing JSON objects from the stream public class RpcEndpoint : EndPoint { private readonly Dictionary> _callbacks @@ -58,11 +57,11 @@ namespace SocketsSample return _paramTypes.TryGetValue(methodName, out types) ? types : null; }); - /* TODO: ?? */ - //if (((Channel)connection.Channel).Reading.IsCompleted) - //{ - // break; - //} + // Is there a better way of detecting that a connection was closed? + if (invocationDescriptor == null) + { + break; + } if (_logger.IsEnabled(LogLevel.Debug)) { diff --git a/samples/SocketsSample/LineInvocationAdapter.cs b/samples/SocketsSample/LineInvocationAdapter.cs index af1dce60b6..8bed0c94c3 100644 --- a/samples/SocketsSample/LineInvocationAdapter.cs +++ b/samples/SocketsSample/LineInvocationAdapter.cs @@ -12,6 +12,11 @@ namespace SocketsSample { var streamReader = new StreamReader(stream); var line = await streamReader.ReadLineAsync(); + if (line == null) + { + return null; + } + var values = line.Split(','); var method = values[1].Substring(1);