Skip to content

Add option for launching in own process group #155

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mattjohnsonpint
Copy link

In order to handle shutdown cleanly in an app, it's important that the application starting the db instance with Start is also the one the calls Stop to shut it down. In the case where an app is running until the user terminates it with a Ctrl-C, the app needs to be able to trap the SIGINT and then call Stop.

Unfortunately, there's some platform differences in how Ctrl-C is propagated to child processes between platforms. On Linux/Mac, the interrupt request is passed only to the parent process, but on Windows it is passed to ALL child processes in the same process group as well. So by the time the parent app goes to call Stop - the server is already terminated.

This PR adds a config flag, OwnProcessGroup which when passed true will make sure that the exec commands that call pg_ctl (and in turn, the postgres server itself) are launched in their own process group. This will change the Ctrl-C behavior on Windows to behave the same as on Linux/Mac.

For good measure, I also set the appropriate flag on Linux/Mac so the behavior is truly consistent in all regards. It's SysProcAttr.Setpgid = true on Linux/Mac, and SysProcAttr.CreationFlags = syscall.CREATE_NEW_PROCESS_GROUP on Windows.

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

Successfully merging this pull request may close these issues.

1 participant