Fix ParallelLoopExecution abandoning in-flight iterations and miscounting MinimumIterations - #807
Merged
imadityaa merged 7 commits intoSep 29, 2026
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Ankit Sharma (ankitsharma-99)
marked this pull request as draft
September 28, 2026 05:20
Replace the iteration-duration heuristic with a shared deadline token. Iterations needed to satisfy MinimumIterations run to completion; later iterations are cancelled and awaited when Duration elapses. Restore the documented MinimumIterations default of 0.
Ankit Sharma (ankitsharma-99)
marked this pull request as ready for review
September 28, 2026 07:45
imadityaa
approved these changes
Sep 28, 2026
Bryan DeYoung (brdeyo)
approved these changes
Sep 28, 2026
Signed-off-by: Ankit Sharma <58849812+ankitsharma-99@users.noreply.github.com>
Signed-off-by: Ankit Sharma <58849812+ankitsharma-99@users.noreply.github.com>
imadityaa
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two defects in
ParallelLoopExecution.ExecuteComponentLoopAsync:Durationelapses. On timeout the loopbreaks out ofTask.WhenAnywithout cancelling or awaiting the child. The child keeps running on the profile token andis only stopped as a side effect of profile shutdown when the loop happens to be the last action. Nothing
awaits its cleanup, so:
FileUploadMonitor's final drain and are not uploaded inthe same run;
currentIterationis incremented twice per pass (at the top oftryand again infinally), so theguards evaluate 1, 3, 5, ... .
MinimumIterations: 1therefore guarantees no completed iteration, andMinimumIterations: Nguarantees only floor(N/2).Example: with children that run for 30 minutes and
Duration: 00:40:00, one iteration completes, a secondstarts with 10 minutes remaining and is abandoned about 10 minutes in. With
Durationequal to the childduration and
MinimumIterations: 1, the only iteration is abandoned at the deadline.Fix
Restores the documented contract (
website/docs/guides/0011-profiles.md): run untilDuration, and letMinimumIterationsguarantee complete iterations.CancellationTokenSource(CancelAfter(Duration)) replaces thetimeoutTaskfield and isshared by all parallel loops.
MinimumIterationsrun with a token linked only to the caller's token, sothey complete even if
Durationelapses.elapses the iteration is cancelled and awaited; no child task is left running when the component returns.
MinimumIterationsdefault remains1, docs corrected to match.DurationandMinimumIterationscorrected.Behavior
Children that run for 30 minutes:
Unchanged: children still run in parallel, unsupported components are skipped, caller cancellation stops all
loops, and child exceptions propagate as before.
Testing
ParallelLoopExecution_CancelsAndAwaitsTheInFlightIterationWhenTheDurationElapsesParallelLoopExecution_CompletesTheMinimumIterationEvenWhenItExceedsTheDurationParallelLoopExecution_CancelsAndAwaitsAnIterationBeyondTheMinimumWhenTheDurationElapsesParallelLoopExecution_LoopsUntilCancelledWhenNoDurationIsDefinedMinimumIterationstests now assert exact completed-iteration counts instead of start counts.VirtualClient.Core.UnitTests: 968 passed, 0 failed, 1 skipped (pre-existing flaky test).Out of scope
A cancelled iteration still emits a
Succeededscenario metric, becauseVirtualClientComponent.ExecuteAsynctreats
OperationCanceledExceptionas success. That behavior is in the base component, not this loop.