Merge branch 'release/2.2'
This commit is contained in:
commit
d7c696f51f
|
|
@ -88,6 +88,8 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
|
||||||
|
|
||||||
public Task TransportTask { get; set; }
|
public Task TransportTask { get; set; }
|
||||||
|
|
||||||
|
public Task PreviousPollTask { get; set; } = Task.CompletedTask;
|
||||||
|
|
||||||
public Task ApplicationTask { get; set; }
|
public Task ApplicationTask { get; set; }
|
||||||
|
|
||||||
public DateTime LastSeenUtc { get; set; }
|
public DateTime LastSeenUtc { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new Tcs every poll to keep track of the poll finishing, so we can properly wait on previous polls
|
||||||
|
var currentRequestTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
|
||||||
await connection.StateLock.WaitAsync();
|
await connection.StateLock.WaitAsync();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -205,17 +208,17 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
|
||||||
{
|
{
|
||||||
var existing = connection.GetHttpContext();
|
var existing = connection.GetHttpContext();
|
||||||
Log.ConnectionAlreadyActive(_logger, connection.ConnectionId, existing.TraceIdentifier);
|
Log.ConnectionAlreadyActive(_logger, connection.ConnectionId, existing.TraceIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
using (connection.Cancellation)
|
using (connection.Cancellation)
|
||||||
{
|
{
|
||||||
// Cancel the previous request
|
// Cancel the previous request
|
||||||
connection.Cancellation?.Cancel();
|
connection.Cancellation?.Cancel();
|
||||||
|
|
||||||
// Wait for the previous request to drain
|
// Always wait for the previous request to drain
|
||||||
await connection.TransportTask;
|
await connection.PreviousPollTask;
|
||||||
|
|
||||||
Log.PollCanceled(_logger, connection.ConnectionId, existing.TraceIdentifier);
|
connection.PreviousPollTask = currentRequestTcs.Task;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the connection as active
|
// Mark the connection as active
|
||||||
|
|
@ -267,6 +270,8 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
|
||||||
|
|
||||||
var resultTask = await Task.WhenAny(connection.ApplicationTask, connection.TransportTask);
|
var resultTask = await Task.WhenAny(connection.ApplicationTask, connection.TransportTask);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
var pollAgain = true;
|
var pollAgain = true;
|
||||||
|
|
||||||
// If the application ended before the transport task then we potentially need to end the connection
|
// If the application ended before the transport task then we potentially need to end the connection
|
||||||
|
|
@ -303,12 +308,6 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pollAgain)
|
if (pollAgain)
|
||||||
{
|
|
||||||
// Otherwise, we update the state to inactive again and wait for the next poll
|
|
||||||
await connection.StateLock.WaitAsync();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (connection.Status == HttpConnectionStatus.Active)
|
|
||||||
{
|
{
|
||||||
// Mark the connection as inactive
|
// Mark the connection as inactive
|
||||||
connection.LastSeenUtc = DateTime.UtcNow;
|
connection.LastSeenUtc = DateTime.UtcNow;
|
||||||
|
|
@ -323,8 +322,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
connection.StateLock.Release();
|
// Artificial task queue
|
||||||
}
|
// This will cause incoming polls to wait until the previous poll has finished updating internal state info
|
||||||
|
currentRequestTcs.TrySetResult(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue