Avoid unobserved exceptions
- Don't throw from AdaptedPipeline.ReadInputAsync - Watch for unobserved exceptions in SampleApp
This commit is contained in:
parent
ba549502e1
commit
7d3bcd2bf8
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
|
@ -34,6 +35,11 @@ namespace SampleApp
|
|||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
TaskScheduler.UnobservedTaskException += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine("Unobserved exception: {0}", e.Exception);
|
||||
};
|
||||
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -63,7 +63,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal
|
|||
catch (Exception ex)
|
||||
{
|
||||
Input.Writer.Complete(ex);
|
||||
throw;
|
||||
|
||||
// Don't rethrow the exception. It should be handled by the Pipeline consumer.
|
||||
return;
|
||||
}
|
||||
} while (bytesRead != 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -119,10 +119,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
|||
|
||||
public Task StopAsync()
|
||||
{
|
||||
_frame.StopAsync();
|
||||
_frame.Input.Reader.CancelPendingRead();
|
||||
|
||||
return _socketClosedTcs.Task;
|
||||
return Task.WhenAll(_frame.StopAsync(), _socketClosedTcs.Task);
|
||||
}
|
||||
|
||||
public virtual Task AbortAsync(Exception error = null)
|
||||
|
|
|
|||
|
|
@ -402,10 +402,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
|||
/// </summary>
|
||||
public Task StopAsync()
|
||||
{
|
||||
if (!_requestProcessingStopping)
|
||||
{
|
||||
_requestProcessingStopping = true;
|
||||
}
|
||||
_requestProcessingStopping = true;
|
||||
Input.Reader.CancelPendingRead();
|
||||
|
||||
return _requestProcessingTask ?? TaskCache.CompletedTask;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue