- Notifications
You must be signed in to change notification settings - Fork 197
Correctly handle sending signal to child process #7738
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
Correctly handle sending signal to child process #7738
Conversation
Calling proc.Kill causes the process to exit immediately, which prevents Beats from executing some clean up functions. Now windows.GenerateConsoleCtrlEvent to send a CTRL+C signal that is haled as a SIGINT, thus allowing the Beat to execute all necessary clean up.
This pull request does not have a backport label. Could you fix it @belimawr? 🙏
|
Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane) |
buildkite test this |
|
💚 Build Succeeded
History
cc @belimawr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. Windows hard-stopping everything is not good, this was really needed! Nice work.
Thank you @blakerouse! Btw, be aware that this PR does not fully fixes the problem, sub process will still be forcefully killed until #7756 is resolved. |
What does this PR do?
Calling proc.Kill causes the process to exit immediately, which
prevents components from executing some clean up functions.
To gracefully terminate the components, on Linux and MacOS SIGTERM
is sent.
On Windows signals are sent to process groups, child process are created
in the same group as the parent, so sending a signal to a child process
causes the Elastic-Agent to receive the signal as well. Therefore child
process need to be created in their own process group.
To do so, the child process needs to be created setting the creation flag
CREATE_NEW_PROCESS_GROUP, which has the side effect of disbling
the CTRL+C signal.
Then to correctly terminate the child process
windows.GenerateConsoleCtrlEvent
is called to send CTRL+BREAK signal that is translated by go Go runtime into a
syscall.SIGINT
, which is already correctly handled by Beats.Why is it important?
It correctly signals components to exit, allowing them to run their cleanup.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration filesI have added tests that prove my fix is effective or that my feature works./changelog/fragments
using the changelog toolI have added an integration test or an E2E test## Disruptive User ImpactHow to test this PR locally
Related issues
Questions to ask yourself