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

Redo signal handling #854

Merged
merged 4 commits into from
Apr 22, 2024
Merged

Redo signal handling #854

merged 4 commits into from
Apr 22, 2024

Conversation

dbussink
Copy link
Collaborator

These changes rework how we do signal handling after #853. It turns out, trying to forward signals is not really what we want.

At the code here is that different platforms behave in different ways with how signals are handled. The specific cause of the remaining issue described in #850 is that on Linux and unix like platforms, the normal behavior on ctrl+c is that all processes in the current group get sent a ctrl+c.

If we forward signals, we receive the ctrl+c twice inside MySQL leading to weird behavior. But we also don't want to ignore the signals either, since a single SIGINT sent to pscale is still something we want to act on. On Windows though, the current signal handling setup does seem to work as desired.

So we have to split things up here per platform. On Unix like platforms, we can use https://pkg.go.dev/syscall#SysProcAttr and set Foreground. That will imply Setpgid as well, which means we get a new process group for the process we're spawning and it attaches it to the foreground. That means now MySQL has the foreground as an independent process group, so it gets the signals appropriately and it's as if we'd directly have started MySQL.

On Windows we keep using the same signal handling logic mostly, but slightly simplified. Lastly, we fix the warning signal for prod branches since on Windows it looks like doesn't actually work.

There looks to be a better approach here with how we start the process
that avoids many other problems with the signals. It is platform
dependent, but given how much better it is, we should use this.
If we set it to the foreground, it will have it's own process ground and
receive signals directly without having to set up any proxying or
forwarding in the CLI itself.
We need this on Windows as there doesn't seem to be a good other way to
have the foreground process and handle signals correctly.
@dbussink dbussink merged commit 30c8290 into main Apr 22, 2024
1 check passed
@dbussink dbussink deleted the dbussink/redo-signal-handling branch April 22, 2024 12:56
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.

2 participants