diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 15035a81b4..7ffa068d88 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -4,6 +4,7 @@ using System; using System.Buffers; using System.Collections.Concurrent; +using System.IO; using System.IO.Pipelines; using System.Security.Authentication; using System.Text; @@ -14,8 +15,8 @@ using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.FlowControl; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; @@ -218,6 +219,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 error = ex; } + catch (IOException ex) + { + Log.RequestProcessingError(ConnectionId, ex); + error = ex; + } catch (Http2ConnectionErrorException ex) { Log.Http2ConnectionError(ConnectionId, ex); @@ -232,9 +238,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 } catch (Exception ex) { + Log.LogWarning(0, ex, CoreStrings.RequestProcessingEndError); error = ex; errorCode = Http2ErrorCode.INTERNAL_ERROR; - throw; } finally { diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 7bf017534b..c20c9ecfc9 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -21,6 +21,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; using Moq; using Xunit; @@ -3425,6 +3426,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await WaitForConnectionStopAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false); } + [Fact] + public void IOExceptionDuringFrameProcessingLoggedAsInfo() + { + var ioException = new IOException(); + _pair.Application.Output.Complete(ioException); + + Assert.Equal(TaskStatus.RanToCompletion, _connection.ProcessRequestsAsync(new DummyApplication(_noopApplication)).Status); + + var logMessage = _logger.Messages.Single(); + + Assert.Equal(LogLevel.Information, logMessage.LogLevel); + Assert.Equal("Connection id \"(null)\" request processing ended abnormally.", logMessage.Message); + Assert.Same(ioException, logMessage.Exception); + } + + [Fact] + public void UnexpectedExceptionDuringFrameProcessingLoggedAWarning() + { + var exception = new Exception(); + _pair.Application.Output.Complete(exception); + + Assert.Equal(TaskStatus.RanToCompletion, _connection.ProcessRequestsAsync(new DummyApplication(_noopApplication)).Status); + + var logMessage = _logger.Messages.Single(); + + Assert.Equal(LogLevel.Warning, logMessage.LogLevel); + Assert.Equal(CoreStrings.RequestProcessingEndError, logMessage.Message); + Assert.Same(exception, logMessage.Exception); + } + private async Task InitializeConnectionAsync(RequestDelegate application) { _connectionTask = _connection.ProcessRequestsAsync(new DummyApplication(application));