From 8f854f7659d245b245bf56d0490e9cdc914356fb Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Mon, 16 Dec 2024 19:41:11 +0100 Subject: [PATCH] Fixed batching completes before all responses are returned. (#7832) --- .../Core/src/Execution/RequestExecutor.cs | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/HotChocolate/Core/src/Execution/RequestExecutor.cs b/src/HotChocolate/Core/src/Execution/RequestExecutor.cs index a46d425415d..841eb72c838 100644 --- a/src/HotChocolate/Core/src/Execution/RequestExecutor.cs +++ b/src/HotChocolate/Core/src/Execution/RequestExecutor.cs @@ -241,47 +241,30 @@ private async IAsyncEnumerable ExecuteBatchStream( } var buffer = new IOperationResult[8]; - int bufferCount; do { - bufferCount = completed.TryPopRange(buffer); + var resultCount = completed.TryPopRange(buffer); - for (var i = 0; i < bufferCount; i++) + for (var i = 0; i < resultCount; i++) { yield return buffer[i]; } - if (bufferCount == 0) + if (completed.IsEmpty && tasks.Count > 0) { - if(tasks.Any(t => !t.IsCompleted)) - { - var task = await Task.WhenAny(tasks); + var task = await Task.WhenAny(tasks); - if (task.Status is not TaskStatus.RanToCompletion) - { - // we await to throw if it's not successful. - await task; - } - - tasks.Remove(task); - } - else + // we await to throw if it's not successful. + if (task.Status is not TaskStatus.RanToCompletion) { - foreach (var task in tasks) - { - if (task.Status is not TaskStatus.RanToCompletion) - { - // we await to throw if it's not successful. - await task; - } - } - - tasks.Clear(); + await task; } + + tasks.Remove(task); } } - while (tasks.Count > 0 || bufferCount > 0); + while (tasks.Count > 0 || !completed.IsEmpty); } private static IOperationRequest WithServices(IOperationRequest request, IServiceProvider services)