Merge branch 'merge/release/2.2-to-master'
This commit is contained in:
commit
bca244f758
|
|
@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Connections
|
||||||
|
|
||||||
public override void Abort(ConnectionAbortedException abortReason)
|
public override void Abort(ConnectionAbortedException abortReason)
|
||||||
{
|
{
|
||||||
ThreadPool.QueueUserWorkItem(cts => ((CancellationTokenSource)cts).Cancel(), _connectionClosedTokenSource);
|
ThreadPool.UnsafeQueueUserWorkItem(cts => ((CancellationTokenSource)cts).Cancel(), _connectionClosedTokenSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
|
|
||||||
var readableBuffer = result.Buffer;
|
var readableBuffer = result.Buffer;
|
||||||
var consumed = readableBuffer.Start;
|
var consumed = readableBuffer.Start;
|
||||||
var examined = readableBuffer.End;
|
var examined = readableBuffer.Start;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1212,7 +1212,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
var ex = new InvalidOperationException(CoreStrings.FormatHeaderNotAllowedOnResponse("Transfer-Encoding", StatusCode));
|
var ex = new InvalidOperationException(CoreStrings.FormatHeaderNotAllowedOnResponse("Transfer-Encoding", StatusCode));
|
||||||
if (!appCompleted)
|
if (!appCompleted)
|
||||||
{
|
{
|
||||||
// Back out of header creation surface exeception in user code
|
// Back out of header creation surface exception in user code
|
||||||
_requestProcessingStatus = RequestProcessingStatus.AppStarted;
|
_requestProcessingStatus = RequestProcessingStatus.AppStarted;
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
|
||||||
public static async Task<bool> AbortAllConnectionsAsync(this ConnectionManager connectionManager)
|
public static async Task<bool> AbortAllConnectionsAsync(this ConnectionManager connectionManager)
|
||||||
{
|
{
|
||||||
var abortTasks = new List<Task>();
|
var abortTasks = new List<Task>();
|
||||||
var canceledException = new ConnectionAbortedException(CoreStrings.ConnectionAbortedDuringServerShutdown);
|
|
||||||
|
|
||||||
connectionManager.Walk(connection =>
|
connectionManager.Walk(connection =>
|
||||||
{
|
{
|
||||||
connection.TransportConnection.Abort(canceledException);
|
connection.TransportConnection.Abort(new ConnectionAbortedException(CoreStrings.ConnectionAbortedDuringServerShutdown));
|
||||||
abortTasks.Add(connection.ExecutionTask);
|
abortTasks.Add(connection.ExecutionTask);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
|
||||||
{
|
{
|
||||||
public class Streams
|
public class Streams
|
||||||
{
|
{
|
||||||
private static readonly ThrowingWriteOnlyStream _throwingResponseStream
|
private static readonly ThrowingWasUpgradedWriteOnlyStream _throwingResponseStream
|
||||||
= new ThrowingWriteOnlyStream(new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded));
|
= new ThrowingWasUpgradedWriteOnlyStream();
|
||||||
private readonly HttpResponseStream _response;
|
private readonly HttpResponseStream _response;
|
||||||
private readonly HttpRequestStream _request;
|
private readonly HttpRequestStream _request;
|
||||||
private readonly WrappingStream _upgradeableResponse;
|
private readonly WrappingStream _upgradeableResponse;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
|
|
||||||
public void OnCompleted(Action continuation)
|
public void OnCompleted(Action continuation)
|
||||||
{
|
{
|
||||||
ThreadPool.QueueUserWorkItem(state => ((Action)state)(), continuation);
|
ThreadPool.UnsafeQueueUserWorkItem(state => ((Action)state)(), continuation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnsafeOnCompleted(Action continuation)
|
public void UnsafeOnCompleted(Action continuation)
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,8 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
|
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
|
||||||
{
|
{
|
||||||
public class ThrowingWriteOnlyStream : WriteOnlyStream
|
public class ThrowingWasUpgradedWriteOnlyStream : WriteOnlyStream
|
||||||
{
|
{
|
||||||
private readonly Exception _exception;
|
|
||||||
|
|
||||||
public ThrowingWriteOnlyStream(Exception exception)
|
|
||||||
{
|
|
||||||
_exception = exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool CanSeek => false;
|
public override bool CanSeek => false;
|
||||||
|
|
||||||
public override long Length => throw new NotSupportedException();
|
public override long Length => throw new NotSupportedException();
|
||||||
|
|
@ -28,13 +21,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Write(byte[] buffer, int offset, int count)
|
public override void Write(byte[] buffer, int offset, int count)
|
||||||
=> throw _exception;
|
=> throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded);
|
||||||
|
|
||||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||||
=> throw _exception;
|
=> throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded);
|
||||||
|
|
||||||
public override void Flush()
|
public override void Flush()
|
||||||
=> throw _exception;
|
=> throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded);
|
||||||
|
|
||||||
public override long Seek(long offset, SeekOrigin origin)
|
public override long Seek(long offset, SeekOrigin origin)
|
||||||
=> throw new NotSupportedException();
|
=> throw new NotSupportedException();
|
||||||
|
|
@ -88,6 +88,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// This is unexpected.
|
||||||
|
Log.ConnectionError(ConnectionId, ex);
|
||||||
|
|
||||||
inputError = ex;
|
inputError = ex;
|
||||||
outputError = ex;
|
outputError = ex;
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +110,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||||
|
|
||||||
// We're done with the socket now
|
// We're done with the socket now
|
||||||
_socket.Dispose();
|
_socket.Dispose();
|
||||||
ThreadPool.QueueUserWorkItem(state => ((LibuvConnection)state).CancelConnectionClosedToken(), this);
|
ThreadPool.UnsafeQueueUserWorkItem(state => ((LibuvConnection)state).CancelConnectionClosedToken(), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
@ -240,6 +243,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// This is unexpected.
|
||||||
Log.ConnectionError(ConnectionId, uvError);
|
Log.ConnectionError(ConnectionId, uvError);
|
||||||
return new IOException(uvError.Message, uvError);
|
return new IOException(uvError.Message, uvError);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
|
||||||
{
|
{
|
||||||
if (!_doingWork)
|
if (!_doingWork)
|
||||||
{
|
{
|
||||||
System.Threading.ThreadPool.QueueUserWorkItem(_doWorkCallback, this);
|
System.Threading.ThreadPool.UnsafeQueueUserWorkItem(_doWorkCallback, this);
|
||||||
_doingWork = true;
|
_doingWork = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
|
||||||
|
|
||||||
_receiver.Dispose();
|
_receiver.Dispose();
|
||||||
_sender.Dispose();
|
_sender.Dispose();
|
||||||
ThreadPool.QueueUserWorkItem(state => ((SocketConnection)state).CancelConnectionClosedToken(), this);
|
ThreadPool.UnsafeQueueUserWorkItem(state => ((SocketConnection)state).CancelConnectionClosedToken(), this);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
|
{
|
||||||
|
public class ThrowingWasUpgradedWriteOnlyStreamTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task ThrowsOnWrite()
|
||||||
|
{
|
||||||
|
var stream = new ThrowingWasUpgradedWriteOnlyStream();
|
||||||
|
|
||||||
|
Assert.True(stream.CanWrite);
|
||||||
|
Assert.False(stream.CanRead);
|
||||||
|
Assert.False(stream.CanSeek);
|
||||||
|
Assert.False(stream.CanTimeout);
|
||||||
|
Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, Assert.Throws<InvalidOperationException>(() => stream.Write(new byte[1], 0, 1)).Message);
|
||||||
|
Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, (await Assert.ThrowsAsync<InvalidOperationException>(() => stream.WriteAsync(new byte[1], 0, 1))).Message);
|
||||||
|
Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, Assert.Throws<InvalidOperationException>(() => stream.Flush()).Message);
|
||||||
|
Assert.Equal(CoreStrings.ResponseStreamWasUpgraded, (await Assert.ThrowsAsync<InvalidOperationException>(() => stream.FlushAsync())).Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|
||||||
{
|
|
||||||
public class ThrowingWriteOnlyStreamTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public async Task ThrowsOnWrite()
|
|
||||||
{
|
|
||||||
var ex = new Exception("my error");
|
|
||||||
var stream = new ThrowingWriteOnlyStream(ex);
|
|
||||||
|
|
||||||
Assert.True(stream.CanWrite);
|
|
||||||
Assert.False(stream.CanRead);
|
|
||||||
Assert.False(stream.CanSeek);
|
|
||||||
Assert.False(stream.CanTimeout);
|
|
||||||
Assert.Same(ex, Assert.Throws<Exception>(() => stream.Write(new byte[1], 0, 1)));
|
|
||||||
Assert.Same(ex, await Assert.ThrowsAsync<Exception>(() => stream.WriteAsync(new byte[1], 0, 1)));
|
|
||||||
Assert.Same(ex, Assert.Throws<Exception>(() => stream.Flush()));
|
|
||||||
Assert.Same(ex, await Assert.ThrowsAsync<Exception>(() => stream.FlushAsync()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
|
||||||
|
|
||||||
_isClosed = true;
|
_isClosed = true;
|
||||||
|
|
||||||
ThreadPool.QueueUserWorkItem(state =>
|
ThreadPool.UnsafeQueueUserWorkItem(state =>
|
||||||
{
|
{
|
||||||
var self = (InMemoryTransportConnection)state;
|
var self = (InMemoryTransportConnection)state;
|
||||||
self._connectionClosedTokenSource.Cancel();
|
self._connectionClosedTokenSource.Cancel();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue