PowerShell/Polaris

Polaris exits immediately when run in a container

pcgeek86 opened this issue · 5 comments

Problem Statement

When I run Start-Polaris inside a container, the container exits immediately because the command is asynchronous. I tried adding a Start-Sleep -Seconds 100 command after Start-Polaris, but this caused the route handlers to block, so the web server was non-responsive.

Proposed Solution

Add a -Wait parameter to the Start-Polaris command, to block script execution and force the command to run synchronously.

I found a container example here, which also uses the Start-Sleep approach, but as mentioned in the OP, that causes the process to block.

https://github.com/PowerShell/Polaris/pull/145/files#diff-f4d1fe67442cfa70093f78fb980a58c4

Hi @pcgeek86,

Thanks for submitting the issue! We do have a method better than sleep but it isn't documented very well.

Polaris uses a callback bridge to fire events so you can hold a process open using Wait-Event like this:

while ($Polaris.Listener.IsListening) {
   Wait-Event callbackeventbridge.callbackcomplete
}

This is a fairly common scenario, not specific to containers so it might be a good idea to add a switch or something to the Start-Polaris command.

I'm not sure what a good name for the switch would be though... Start-Polaris -Wait or Start-Polaris -HoldThreadOpen or all sound to me like 'Micah sucks at naming things!'

Thanks Micah! I will give that a shot.

Considering that Start-Process has a -Wait parameter, this seems like a good convention to follow!

@TylerLeonhardt - What do you think about adding a -Wait parameter?

@pcgeek86 I haven't tested to see if this still works. But, here is a repo from when I was playing with running Polaris in a container.

https://github.com/jeremymcgee73/PolarisDocker