Keep waiting for a per-user task that started between two reads - #122
Open
Laurent Zogaj (26zl) wants to merge 1 commit into
Open
Laurent Zogaj (26zl) wants to merge 1 commit into
Laurent Zogaj (26zl) wants to merge 1 commit into
Conversation
Invoke-DevConfigUnelevatedCommand polls the task with two separate reads: Get-ScheduledTask for the state, then Get-ScheduledTaskInfo for the result. If the task starts between them, the first read still says Ready while the second already reports 0x41301 (SCHED_S_TASK_RUNNING). $hasStarted flips, the state is not Running, the loop exits, 267009 is returned as the command's exit code, and the finally block stops the task that is still uninstalling. Treat 0x41301 as "still running" in the loop condition.
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.
Same background as my other two Uninstall PRs. This one is a timing issue in the per-user task polling that I could only trigger by forcing the timing.
Invoke-DevConfigUnelevatedCommandpolls its scheduled task with two separate reads,Get-ScheduledTaskfor the state and thenGet-ScheduledTaskInfofor the result, about 200 ms apart. If the task starts between them, the first read still saysReadywhile the second already reports0x41301(SCHED_S_TASK_RUNNING). That flips$hasStarted, the loop condition checks the stale state, and the loop exits with the task still running: the function returns267009as the exit code with an empty output, the cleanup step is flagged as failed, and thefinallyblock stops the task, killing the uninstaller mid-run.The fix treats
0x41301as "still running" in the loop condition. The opposite order (task finishes between the reads) already works, because the state read saysRunning.Reproduced on Windows 11 Pro 25H2 (build 26200.9550), pwsh 7.6.6, with the real function and a temporary task under my own user, with
Start-ScheduledTaskwrapped so the task starts between the two reads. Before:ExitCode=267009, empty output,Stop-ScheduledTaskcalled on the running task. After:ExitCode=0, outputfine, no stop. On an idle machine the task is running well within the loop's initial 500 ms sleep, so 20 unforced runs never hit the window here; it opens when the scheduler is slower than that, and an Uninstall starts one such task per per-user package.Only
src/is touched; the signed copy is left to the sign pipeline.Thanks for having a look.