Merge branch 'release/2.1' into dev

This commit is contained in:
Stephen Halter 2018-06-28 11:24:55 -07:00
commit 2ab22ac55a
8 changed files with 20 additions and 16 deletions

View File

@ -205,10 +205,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
}
}
}
protected override void AbortCore(ConnectionAbortedException abortReason)
{
}
}
// Copied from https://github.com/aspnet/benchmarks/blob/dev/src/Benchmarks/Middleware/PlaintextMiddleware.cs

View File

@ -25,5 +25,7 @@ namespace Microsoft.AspNetCore.Connections
// ConnectioContext.Abort()
Features.Get<IConnectionLifetimeFeature>()?.Abort();
}
public virtual void Abort() => Abort(new ConnectionAbortedException("The connection was aborted by the application."));
}
}

View File

@ -65,8 +65,6 @@ namespace Microsoft.AspNetCore.Connections
public CancellationToken ConnectionClosed { get; set; }
public void Abort() => Abort(abortReason: null);
public override void Abort(ConnectionAbortedException abortReason)
{
ThreadPool.QueueUserWorkItem(cts => ((CancellationTokenSource)cts).Cancel(), _connectionClosedTokenSource);

View File

@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
(_, state) => ((HttpConnection)state).OnInputOrOutputCompleted(),
connection);
await AsTask(lifetimeFeature.ConnectionClosed);
await CancellationTokenAsTask(lifetimeFeature.ConnectionClosed);
connection.OnConnectionClosed();
@ -99,8 +99,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
}
}
private Task AsTask(CancellationToken token)
private static Task CancellationTokenAsTask(CancellationToken token)
{
if (token.IsCancellationRequested)
{
return Task.CompletedTask;
}
// Transports already dispatch prior to tripping ConnectionClosed
// since application code can register to this token.
var tcs = new TaskCompletionSource<object>();
token.Register(() => tcs.SetResult(null));
return tcs.Task;

View File

@ -55,14 +55,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal
public CancellationToken ConnectionClosed { get; set; }
// DO NOT remove this override to ConnectionContext.Abort(). Doing so would cause
// any TransportConnection that does not override Abort() or calls base.Abort()
// DO NOT remove this override to ConnectionContext.Abort. Doing so would cause
// any TransportConnection that does not override Abort or calls base.Abort
// to stack overflow when IConnectionLifetimeFeature.Abort() is called.
// That said, all derived types should override this method should override
// this implementation of Abort because canceling pending output reads is not
// sufficient to abort the connection if there is backpressure.
public override void Abort(ConnectionAbortedException abortReason)
{
AbortCore(abortReason);
Output.CancelPendingRead();
}
protected abstract void AbortCore(ConnectionAbortedException abortReason);
}
}

View File

@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
}
}
protected override void AbortCore(ConnectionAbortedException abortReason)
public override void Abort(ConnectionAbortedException abortReason)
{
_abortReason = abortReason;
Output.CancelPendingRead();

View File

@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
}
}
protected override void AbortCore(ConnectionAbortedException abortReason)
public override void Abort(ConnectionAbortedException abortReason)
{
_abortReason = abortReason;
Output.CancelPendingRead();

View File

@ -2459,7 +2459,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
await context.Response.Body.WriteAsync(scratchBuffer, 0, scratchBuffer.Length);
await Task.Delay(10);
}
appCompletedTcs.SetResult(null);
}, new TestServiceContext(LoggerFactory), listenOptions))
{