Skip to content

Commit

Permalink
Fixed batching completes before all responses are returned. (#7832)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Dec 16, 2024
1 parent 4e4ec6f commit 8f854f7
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions src/HotChocolate/Core/src/Execution/RequestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,47 +241,30 @@ private async IAsyncEnumerable<IOperationResult> 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)
Expand Down

0 comments on commit 8f854f7

Please sign in to comment.