diff --git a/Src/Compilers/Core/VBCSCompiler/ServerDispatcher.Connection.cs b/Src/Compilers/Core/VBCSCompiler/ServerDispatcher.Connection.cs index 3925335629e3db5f7aa166f336fec0427d3d4ee1..160cfbd66c4af15aed6d2351a0c3c14e1fc7a514 100644 --- a/Src/Compilers/Core/VBCSCompiler/ServerDispatcher.Connection.cs +++ b/Src/Compilers/Core/VBCSCompiler/ServerDispatcher.Connection.cs @@ -41,7 +41,17 @@ private class Connection /// public Connection(NamedPipeServerStream pipeStream, IRequestHandler handler) { - this.LoggingIdentifier = pipeStream.SafePipeHandle.DangerousGetHandle().ToInt32(); + try + { + this.LoggingIdentifier = pipeStream.SafePipeHandle.DangerousGetHandle().ToInt32(); + } + catch (Exception e) + { + // We shouldn't fail just because we don't have a good logging identifier + this.LoggingIdentifier = new Random().Next(); + Log("Exception {0} while setting logging identifier; setting to {1}", + e.Message, this.LoggingIdentifier); + } this.pipeStream = pipeStream; this.handler = handler; } diff --git a/Src/Compilers/Core/VBCSCompiler/ServerDispatcher.cs b/Src/Compilers/Core/VBCSCompiler/ServerDispatcher.cs index 31911a85ac0f72ed35ef9288fe3b8df8ba696538..8566ca124572470c97679f0c9c85ed0438ad08f1 100644 --- a/Src/Compilers/Core/VBCSCompiler/ServerDispatcher.cs +++ b/Src/Compilers/Core/VBCSCompiler/ServerDispatcher.cs @@ -254,7 +254,18 @@ private async Task DispatchConnection(NamedPipeServerStream pipeStream) Connection connection = new Connection(pipeStream, handler); - await connection.ServeConnection().ConfigureAwait(false); + try + { + await connection.ServeConnection().ConfigureAwait(false); + } + catch (ObjectDisposedException e) + { + // If the client closes the pipe while we're reading or writing + // we'll get an object disposed exception on the pipe + // Log the failure and continue + CompilerServerLogger.Log( + "Client pipe closed: received exception " + e.Message); + } // The connection should be finished ConnectionCompleted(connection);