Skip to content

Commit 23cf377

Browse files
committed
Fixed batching completes before all responses are returned. (#7832)
1 parent 6747630 commit 23cf377

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

src/HotChocolate/Core/src/Execution/RequestExecutor.cs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -241,47 +241,30 @@ private async IAsyncEnumerable<IOperationResult> ExecuteBatchStream(
241241
}
242242

243243
var buffer = new IOperationResult[8];
244-
int bufferCount;
245244

246245
do
247246
{
248-
bufferCount = completed.TryPopRange(buffer);
247+
var resultCount = completed.TryPopRange(buffer);
249248

250-
for (var i = 0; i < bufferCount; i++)
249+
for (var i = 0; i < resultCount; i++)
251250
{
252251
yield return buffer[i];
253252
}
254253

255-
if (bufferCount == 0)
254+
if (completed.IsEmpty && tasks.Count > 0)
256255
{
257-
if(tasks.Any(t => !t.IsCompleted))
258-
{
259-
var task = await Task.WhenAny(tasks);
256+
var task = await Task.WhenAny(tasks);
260257

261-
if (task.Status is not TaskStatus.RanToCompletion)
262-
{
263-
// we await to throw if it's not successful.
264-
await task;
265-
}
266-
267-
tasks.Remove(task);
268-
}
269-
else
258+
// we await to throw if it's not successful.
259+
if (task.Status is not TaskStatus.RanToCompletion)
270260
{
271-
foreach (var task in tasks)
272-
{
273-
if (task.Status is not TaskStatus.RanToCompletion)
274-
{
275-
// we await to throw if it's not successful.
276-
await task;
277-
}
278-
}
279-
280-
tasks.Clear();
261+
await task;
281262
}
263+
264+
tasks.Remove(task);
282265
}
283266
}
284-
while (tasks.Count > 0 || bufferCount > 0);
267+
while (tasks.Count > 0 || !completed.IsEmpty);
285268
}
286269

287270
private static IOperationRequest WithServices(IOperationRequest request, IServiceProvider services)

0 commit comments

Comments
 (0)