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

Add setpgid for all called commands #1494

Merged
merged 2 commits into from
Jul 28, 2021
Merged

Add setpgid for all called commands #1494

merged 2 commits into from
Jul 28, 2021

Conversation

eikenb
Copy link
Contributor

@eikenb eikenb commented Jul 27, 2021

Need to make sure signals are sent to all processes as sub-shells interfere with signal propagation. Using Setpgid to create a process group for the command and all it's subprocesses fixes this by allowing child to send the signals to the pgid, which thus gets sent to all processes in that group.

This is required for upcoming change to use sub-shells for all executed commands to eliminate need for shell parsing.

With this change it is always set to true and the pgid is always used to send signals to the process(es).

In the future it could be made configurable if needed.

Might be easier to review using the commits. The second commit is test cleanups and fixes where the first one contains the new code and tests.

@eikenb eikenb requested a review from a team July 27, 2021 23:01
@eikenb eikenb force-pushed the child-set-process-group branch from 41460d9 to 13b5204 Compare July 27, 2021 23:06
Copy link
Contributor

@findkim findkim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍

child/child.go Outdated Show resolved Hide resolved
@eikenb eikenb force-pushed the child-set-process-group branch from 13b5204 to 306ce90 Compare July 28, 2021 18:49
eikenb added 2 commits July 28, 2021 11:58
Need to make sure signals are sent to all processes as sub-shells
interfere with signal propagation. Using Setpgid to create a process
group for the command and all it's subprocesses fixes this by allowing
child to send the signals to the pgid, which thus gets sent to all
processes in that group.

This is required for upcoming change to use sub-shells for all executed
commands to eliminate need for shell parsing.

With this change it is always set to true and the pgid is always used to
send signals to the process(es).

In the future it could be made configurable if needed.
Small issue with subshells sending text to STDERR about the signal
received, breaking the text check (result of sending signals to process
group). Changed them to only check STDOUT, where the test text is sent.

Previously used a sleep time of 500 milliseconds when 50 worked fine.
This sped up the child tests a lot.

Everything else are cleaning up lots of useless checks, hardcoded times,
and replace subshell test calls use of bash with standard /bin/sh.
@eikenb eikenb force-pushed the child-set-process-group branch from 306ce90 to 7d17648 Compare July 28, 2021 18:59
@eikenb eikenb merged commit 518b957 into master Jul 28, 2021
@eikenb eikenb deleted the child-set-process-group branch July 28, 2021 20:36
@eikenb eikenb added this to the 0.26.1 milestone Jul 29, 2021
amCap1712 added a commit to amCap1712/consul-template that referenced this pull request Nov 26, 2023
hashicorp#1494 added the setpgid setting to ensure signals are propagated to all
processes and not just the subshell. However, this might not always be
desirable.

For instance, servers like uWSGI run workers in subprocesses and wait
for workers to finish processing active requests for a while before
restarting them to support graceful reloading. consul-template sending
the reload signal to all processes, sends singals to these worker
processes in uWSGI as well which can interfere with graceful reloads.

Currently, we are working around this by using the array form of the
command which does not set the pgid on the child process. But I feel
it might be useful to make this option configurable as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants