Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
BlackbirdSR71Est opened this issue Oct 28, 2020 · 1 comment
Open

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

BlackbirdSR71Est opened this issue Oct 28, 2020 · 1 comment

Comments

@BlackbirdSR71Est
Copy link

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.

@JFLarvoire
Copy link
Owner

Hi,

thanks for the feedback.
If you're confident that your fix resolves the issue you mentioned, please do a pull request for the original script with just that change.
I'll review it and, if it also looks good to me, I'll merge it in.

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

No branches or pull requests

2 participants