Lower log severity for opening internal libuv pipe (#6636)

Addresses #4741
This commit is contained in:
Stephen Halter 2019-01-14 12:29:49 -08:00 committed by GitHub
parent 7f7723bdf2
commit cd0eab88ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -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.");
}
}
}

View File

@ -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<UvException>(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);
}