Repository navigation
Start no more work once an abort is requested between the engines' checks - #114
Merged
Merged
Conversation
…ecks Request-PkAbort and Ctrl+C only raise a flag; the engines stop on their token, which Test-PkAbortSignal cancels, and each main loop called it only after its launch step. So an abort requested before a runspace batch, or by a -ResultHandler, -NextJobProvider or the dispatcher's -PollCallback, still started a round of workers or programs first, and one raised by -JobFinalize had the dispatcher ask -GroupProvider for more groups. Both main loops now check the flag first, the dispatcher checks it again after -PollCallback, and the runspace engine's launch loop reads it per job. Harness section O covers each of those five cases.
…e it starts With the dispatcher now checking for an abort before it asks for any group, a batch started while an abort is in force never handed its commands to the dispatcher, so they came back with no results. The batch now reports each one as aborted itself. The harness's aborted-group callback test raises its abort once the group is built, since one already in force means no group is asked for, and section O checks that case for the dispatcher.
HalRiveria
force-pushed
the
fix/abort-between-checks
branch
from
December 3, 2026 00:29
116c0fa to
32dd726
Compare
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.
Depends on #113, merge after it.
What was wrong:
Request-PkAbortand Ctrl+C only raise a flag. The engines stop on their token, whichTest-PkAbortSignalcancels when it sees the flag, and each engine's main loop called it only after its launch step. So an abort raised between two checks let the engine start one more round of work first:Request-PkAbortbeforeInvoke-PkRunspaceBatch(8 jobs,-MaxConcurrent 4): 4 workers ran before the run drained them.-ResultHandlerthat requests an abort (20 jobs,-MaxConcurrent 2): the slots its results freed were refilled, so 4 ran.-NextJobProviderthat requests an abort: it was asked again until the slots were full.-PollCallbackrequesting an abort on its first call (6 jobs,-MaxConcurrent 3): 3 programs started on that pass.-JobFinalize(or-GroupCompleteCallback, or Ctrl+C during the dispatcher's wait): the next pass asked-GroupProviderfor another group and ran-JobBuilderon it before stopping.What changed:
Both main loops check the flag first, before launching or asking for groups.
The dispatcher checks it again after
-PollCallback.The runspace engine's launch loop reads it before each job, so a
-NextJobProviderthat requests an abort isn't asked again.With an abort already in force, the dispatcher now asks
-GroupProviderfor nothing.Invoke-PkProcessBatchhands its commands to the dispatcher as one group, so in that case it now reports each command as aborted itself (before, the group was fetched and its commands came back aborted).Each check reads the flag and calls
Test-PkAbortSignalonly when it's set. Reading the flag costs less than a function call on Windows PowerShell 5.1.How it was tested: harness section O has one case for each scenario above, plus one for the dispatcher with an abort already in force. None of them calls
Test-PkAbortSignalafterRequest-PkAbort. Section T's existing batch test (an abort in force: every command comes back aborted) failed with the dispatcher change alone and passes with the batch change. Its aborted-group callback test now raises its abort from-JobBuilder, once the group exists.Before the fix (Windows PowerShell 5.1 and PowerShell 7, the same on both):
After: all five pass (
ran 0 of 8,ran 2 of 20,asked 2 times, ran 2,started 0 of 6,asked for 1 group(s), 0 built after the abort).The job a
-NextJobProviderreturns from the call that requested the abort still runs, since the check comes before each call.Full harness: all 755 assertions pass on Windows PowerShell 5.1 and on PowerShell 7.