Skip to content

Start no more work once an abort is requested between the engines' checks - #114

Merged
HalRiveria merged 2 commits into
mainfrom
fix/abort-between-checks
Dec 3, 2026
Merged

HalRiveria merged 2 commits into
mainfrom
fix/abort-between-checks

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

Depends on #113, merge after it.

What was wrong: Request-PkAbort and Ctrl+C only raise a flag. The engines stop on their token, which Test-PkAbortSignal cancels 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-PkAbort before Invoke-PkRunspaceBatch (8 jobs, -MaxConcurrent 4): 4 workers ran before the run drained them.
  • A -ResultHandler that requests an abort (20 jobs, -MaxConcurrent 2): the slots its results freed were refilled, so 4 ran.
  • A -NextJobProvider that requests an abort: it was asked again until the slots were full.
  • The dispatcher's -PollCallback requesting an abort on its first call (6 jobs, -MaxConcurrent 3): 3 programs started on that pass.
  • An abort raised by -JobFinalize (or -GroupCompleteCallback, or Ctrl+C during the dispatcher's wait): the next pass asked -GroupProvider for another group and ran -JobBuilder on 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 -NextJobProvider that requests an abort isn't asked again.

  • With an abort already in force, the dispatcher now asks -GroupProvider for nothing. Invoke-PkProcessBatch hands 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-PkAbortSignal only 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-PkAbortSignal after Request-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):

[FAIL] runspace jobs: an abort requested before the run starts no worker (ran 4 of 8)
[FAIL] runspace jobs: the slots a -ResultHandler frees after requesting an abort aren't refilled (ran 4 of 20)
[FAIL] runspace jobs: -NextJobProvider isn't asked again once it requests an abort (asked 4 times, ran 4)
[FAIL] dispatch: a -PollCallback that requests an abort starts nothing more on that pass (started 3 of 6)
[FAIL] dispatch: a -JobFinalize that requests an abort gets no more groups from -GroupProvider (asked for 2 group(s), 1 built after the abort)

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 -NextJobProvider returns 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.

@HalRiveria
HalRiveria added this pull request to stack #118 December 3, 2026 00:28
Base automatically changed from fix/drive-relative-cmd-quoting to main December 3, 2026 00:29
…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
HalRiveria force-pushed the fix/abort-between-checks branch from 116c0fa to 32dd726 Compare December 3, 2026 00:29
@HalRiveria
HalRiveria merged commit 46034a1 into main Dec 3, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the fix/abort-between-checks branch December 3, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants