Skip to content

Getting stuck in Remove-PSThread in the finally block #28

@BlackbirdSR71Est

Description

@BlackbirdSR71Est

Hi,

Thank you for creating this Powershell Windows Service template.

I ran into an issue with the template in the part where Service part of the code fails with some exception and the logic falls into the "finally" block of the code. As part of the cleanup, "Get-PSThread | Remove-PSThread" is being performed. The Remove-PSThread will call Receive-PSThread to release the resources. The problem is that EndInvoke() method being used in the function will wait for the job to be finished and in this case, we are waiting for a message from the SCM (Receive-PipeMessage) and it may never come. I have tried to replace the EndInvoke() call with the Stop() call which is supposed to kill the job but I am still getting stuck over the call. In short, I am trying to

Start-PipeHandlerThread -pipeName "ControlTest" # Start the thread
Get-PSThread | Remove-PSThread # Shutting it down before any message has been received

The solution I have used to get around in getting stuck in the "finally" block is to inject a message to the named pipe before the cleanup by using Send-PipeMessage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions