From a7a7ccd91b8444a90777ce31a6f0fe8b7b7ec9b7 Mon Sep 17 00:00:00 2001 From: Dave Glick Date: Thu, 20 Sep 2018 11:39:36 -0400 Subject: [PATCH] Better protection for disposed pipe from caller --- .../PipeLoggerServer.cs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/MsBuildPipeLogger.Server/PipeLoggerServer.cs b/src/MsBuildPipeLogger.Server/PipeLoggerServer.cs index 4f7286e..84a60b9 100644 --- a/src/MsBuildPipeLogger.Server/PipeLoggerServer.cs +++ b/src/MsBuildPipeLogger.Server/PipeLoggerServer.cs @@ -45,6 +45,10 @@ public PipeLoggerServer(PipeStream pipeStream) { // The client broke the stream so we're done } + catch (ObjectDisposedException) + { + // The pipe was disposed by the caller + } // Add a final 0 (BinaryLogRecordKind.EndOfFile) into the stream in case the BuildEventArgsReader is waiting for a read Buffer.Write(new byte[1] { 0 }, 0, 1); @@ -69,20 +73,12 @@ public bool Read() return false; } - try + BuildEventArgs args = _buildEventArgsReader.Read(); + if (args != null) { - BuildEventArgs args = _buildEventArgsReader.Read(); - if (args != null) - { - Dispatch(args); - return true; - } + Dispatch(args); + return true; } - catch (EndOfStreamException) - { - // Nothing else to read - } - return false; }