diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs index 24d3ee2ff9..71442c8650 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal dispatchPipe.Init(Thread.Loop, Thread.QueueCloseHandle, true); pipe.Accept(dispatchPipe); - // Ensure client sends "Kestrel" before adding pipe to _dispatchPipes. + // Ensure client sends _pipeMessage before adding pipe to _dispatchPipes. var readContext = new PipeReadContext(this); dispatchPipe.ReadStart( (handle, status2, state) => ((PipeReadContext)state).AllocCallback(handle, status2), @@ -228,6 +228,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal public void ReadCallback(UvStreamHandle dispatchPipe, int status) { + if (status == LibuvConstants.EOF && _bytesRead == 0) + { + // This is an unexpected immediate termination of the dispatch pipe most likely caused by an + // external process scanning the pipe, so don't we don't log it too severely. + // https://github.com/aspnet/AspNetCore/issues/4741 + + dispatchPipe.Dispose(); + _bufHandle.Free(); + _listener.Log.LogDebug("An internal pipe was opened unexpectedly."); + return; + } + try { dispatchPipe.Libuv.ThrowIfErrored(status); @@ -254,7 +266,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } else { - throw new IOException("Bad data sent over Kestrel pipe."); + throw new IOException("Bad data sent over an internal pipe."); } } } diff --git a/src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs index 394ea3250a..b1a338bd56 100644 --- a/src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs +++ b/src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -196,9 +196,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests await listenerPrimary.DisposeAsync(); await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(5)); - Assert.Equal(1, logger.TotalErrorsLogged); - var errorMessage = logger.Messages.First(m => m.LogLevel == LogLevel.Error); - Assert.Equal(TestConstants.EOF, Assert.IsType(errorMessage.Exception).StatusCode); + Assert.Equal(0, logger.TotalErrorsLogged); + + var logMessage = logger.Messages.Single(m => m.Message == "An internal pipe was opened unexpectedly."); + Assert.Equal(LogLevel.Debug, logMessage.LogLevel); }