Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed batching completes before all responses are returned. #7832

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading