Repository navigation
Set-PkMessageHandler throws in worker code - #95
Merged
Merged
Conversation
Two of the batch's own closures called Complete-PkProcess and Write-PkMessage by name. A .GetNewClosure() block only sees global functions, so a batch failed with "'Complete-PkProcess' is not recognized" when the kit was loaded for one module only. They're captured up front now, like the private helpers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A worker given the function (-SharedFunctionNames takes it) could set a handler made in its own runspace, which the main thread then ran for every message. Running another runspace's scriptblock can hang or crash PowerShell. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A worker could call
Set-PkMessageHandler:-SharedFunctionNamesaccepts it, and the worker-safety check can be off or not see the call. The handler was then a scriptblock made in the worker's runspace, which the main thread ran for every message after that. Running another runspace's scriptblock can hang or crash PowerShell (it's the second of the README's two worker rules).Set-PkMessageHandlerthrows in worker code,$nullincluded, and leaves the handler as it was. The message says to set it on the main thread before starting the workers.This changes behavior for a worker that set a handler and got away with it.
Tests
Section M shares the function with a worker that sets a handler, and with one that resets it to
$null.Set-PkMessageHandler throws in a worker, for a handler or $null(nothing thrown) andand leaves the handler as it was.🤖 Generated with Claude Code