Improve exception handling in Http2Connection.ProcessRequestsAsync (#2787)
This commit is contained in:
parent
5378900e0c
commit
c0557cfca7
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue