Skip to content

Commit cd0eab8

Browse files
authored
Lower log severity for opening internal libuv pipe (#6636)
Addresses #4741
1 parent 7f7723b commit cd0eab8

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerPrimary.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private void OnListenPipe(UvStreamHandle pipe, int status, UvException error)
8989
dispatchPipe.Init(Thread.Loop, Thread.QueueCloseHandle, true);
9090
pipe.Accept(dispatchPipe);
9191

92-
// Ensure client sends "Kestrel" before adding pipe to _dispatchPipes.
92+
// Ensure client sends _pipeMessage before adding pipe to _dispatchPipes.
9393
var readContext = new PipeReadContext(this);
9494
dispatchPipe.ReadStart(
9595
(handle, status2, state) => ((PipeReadContext)state).AllocCallback(handle, status2),
@@ -228,6 +228,18 @@ public LibuvFunctions.uv_buf_t AllocCallback(UvStreamHandle dispatchPipe, int su
228228

229229
public void ReadCallback(UvStreamHandle dispatchPipe, int status)
230230
{
231+
if (status == LibuvConstants.EOF && _bytesRead == 0)
232+
{
233+
// This is an unexpected immediate termination of the dispatch pipe most likely caused by an
234+
// external process scanning the pipe, so don't we don't log it too severely.
235+
// https://github.com/aspnet/AspNetCore/issues/4741
236+
237+
dispatchPipe.Dispose();
238+
_bufHandle.Free();
239+
_listener.Log.LogDebug("An internal pipe was opened unexpectedly.");
240+
return;
241+
}
242+
231243
try
232244
{
233245
dispatchPipe.Libuv.ThrowIfErrored(status);
@@ -254,7 +266,7 @@ public void ReadCallback(UvStreamHandle dispatchPipe, int status)
254266
}
255267
else
256268
{
257-
throw new IOException("Bad data sent over Kestrel pipe.");
269+
throw new IOException("Bad data sent over an internal pipe.");
258270
}
259271
}
260272
}

src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -196,9 +196,10 @@ public async Task NonListenerPipeConnectionsAreLoggedAndIgnored()
196196
await listenerPrimary.DisposeAsync();
197197
await libuvThreadPrimary.StopAsync(TimeSpan.FromSeconds(5));
198198

199-
Assert.Equal(1, logger.TotalErrorsLogged);
200-
var errorMessage = logger.Messages.First(m => m.LogLevel == LogLevel.Error);
201-
Assert.Equal(TestConstants.EOF, Assert.IsType<UvException>(errorMessage.Exception).StatusCode);
199+
Assert.Equal(0, logger.TotalErrorsLogged);
200+
201+
var logMessage = logger.Messages.Single(m => m.Message == "An internal pipe was opened unexpectedly.");
202+
Assert.Equal(LogLevel.Debug, logMessage.LogLevel);
202203
}
203204

204205

0 commit comments

Comments
 (0)