diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs index 478d29ded9..e52823dc60 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs @@ -216,6 +216,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Task ISocketOutput.WriteAsync(ArraySegment buffer, bool immediate, CancellationToken cancellationToken) { + if (!immediate) + { + // immediate==false calls always return complete tasks, because there is guaranteed + // to be a subsequent immediate==true call which will go down the following code-path + Write( + buffer, + (error, state) => { }, + null, + immediate: false); + return TaskUtilities.CompletedTask; + } + // TODO: Optimize task being used, and remove callback model from the underlying Write var tcs = new TaskCompletionSource(); @@ -233,7 +245,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } }, tcs, - immediate: immediate); + immediate: true); return tcs.Task; }