Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Complete FrameConnection.StopyAsync() after connection closed
Browse files Browse the repository at this point in the history
  • Loading branch information
halter73 committed Apr 19, 2017
1 parent e5293be commit ec72961
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class FrameConnection : IConnectionContext, ITimeoutControl
private readonly FrameConnectionContext _context;
private readonly Frame _frame;
private readonly List<IConnectionAdapter> _connectionAdapters;
private readonly TaskCompletionSource<bool> _frameStartedTcs = new TaskCompletionSource<bool>();
private readonly TaskCompletionSource<bool> _frameStartedTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
private readonly TaskCompletionSource<object> _socketClosedTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);

private long _lastTimestamp;
private long _timeoutTimestamp = long.MaxValue;
Expand Down Expand Up @@ -90,6 +91,7 @@ public async void OnConnectionClosed()
{
Log.ConnectionStop(ConnectionId);
KestrelEventSource.Log.ConnectionStop(this);
_socketClosedTcs.SetResult(null);

// The connection is already in the "aborted" state by this point, but we want to track it
// until RequestProcessingAsync completes for graceful shutdown.
Expand All @@ -105,6 +107,8 @@ public async Task StopAsync()
await _frame.StopAsync();
await (_adaptedPipelineTask ?? Task.CompletedTask);
}

await _socketClosedTcs.Task;
}

public void Abort(Exception ex)
Expand Down

0 comments on commit ec72961

Please sign in to comment.