diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs index 940196ff87..bd2a9ba2e5 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/MessageBody.cs @@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var limit = buffer.Array == null ? inputLengthLimit : Math.Min(buffer.Count, inputLengthLimit); if (limit == 0) { - return 0; + return new ValueTask(0); } var task = _context.SocketInput.ReadAsync(buffer.Array, buffer.Offset, limit); @@ -189,11 +189,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { _context.RejectRequest("Unexpected end of request content"); } - return actual; + return new ValueTask(actual); } else { - return ReadAsyncAwaited(task.AsTask()); + return new ValueTask(ReadAsyncAwaited(task.AsTask())); } } @@ -232,7 +232,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http public override ValueTask ReadAsyncImplementation(ArraySegment buffer, CancellationToken cancellationToken) { - return ReadStateMachineAsync(_context.SocketInput, buffer, cancellationToken); + return new ValueTask(ReadStateMachineAsync(_context.SocketInput, buffer, cancellationToken)); } private async Task ReadStateMachineAsync(SocketInput input, ArraySegment buffer, CancellationToken cancellationToken) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs index 9b647c4c91..7a74140435 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/SocketInputExtensions.cs @@ -21,15 +21,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http if (actual != 0) { - return actual; + return new ValueTask(actual); } else if (fin) { - return 0; + return new ValueTask(0); } } - return input.ReadAsyncAwaited(buffer, offset, count); + return new ValueTask(input.ReadAsyncAwaited(buffer, offset, count)); } private static async Task ReadAsyncAwaited(this SocketInput input, byte[] buffer, int offset, int count)