diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs index f16cf244cb..dd36f28c28 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameRequestStream.cs @@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http case FrameStreamState.Open: if (cancellationToken.IsCancellationRequested) { - return TaskUtilities.GetCancelledZeroTask(); + return TaskUtilities.GetCancelledZeroTask(cancellationToken); } break; case FrameStreamState.Closed: diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs index 8935ac7bda..97f64e3e21 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/TaskUtilities.cs @@ -26,12 +26,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure #endif } - public static Task GetCancelledZeroTask() + public static Task GetCancelledZeroTask(CancellationToken cancellationToken = default(CancellationToken)) { - // Task.FromCanceled doesn't return Task +#if NETSTANDARD1_3 + return Task.FromCanceled(cancellationToken); +#else var tcs = new TaskCompletionSource(); tcs.TrySetCanceled(); return tcs.Task; +#endif } } } \ No newline at end of file