-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[master] RabbitMQ-server does not quit with Ctrl-C #1192
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
Conversation
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.
Hi @sodre!
This is known issue with Dash unfortunately. Do you know other shells where the signal handler is broken?
I didn't have time yet to work on this issue. Depending on Bash as a workaround is ok.
Thank you for your patch!
scripts/rabbitmq-server
Outdated
@@ -1,4 +1,4 @@ | |||
#!/bin/sh -e | |||
#!/bin/bash -e |
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.
You can't hardcode the path to Bash because it could be installed somewhere else. For instance, on various *BSD, Bash is installed as /usr/local/bin/bash
. Please use /usr/bin/env bash
instead.
In the process, you'll have to remove the -e
and add a set -e
(which is also cleaner) after the license.
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.
No problem. these are all good points. I will take care of them soon.
In the interest of keeping all scripts consistent, I would suggest that we change all |
@sodre another thing we have to ask: if you expect this change to go into a future 3.6.x release, please rebase this against |
@gerhard I can change all of them as well but it is probably not needed. The reason is the other runnable scripts, are not using "trap". Let me know if you still want the others changed and I will make it happen. |
Changed it WIP, I am trying to replicate it in another system. |
Folks, docker run -it --rm ubuntu bash
apt-get update
apt-get install -y wget xz-utils erlang-asn1 erlang-base erlang-corba erlang-diameter erlang-edoc erlang-eldap erlang-erl-docgen erlang-eunit erlang-ic erlang-inets erlang-mnesia erlang-nox erlang-odbc erlang-os-mon erlang-parsetools erlang-percept erlang-public-key erlang-runtime-tools erlang-snmp erlang-ssh erlang-ssl erlang-tools erlang-webtool erlang-xmerl libltdl7 libodbc1 libpopt0
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.9/rabbitmq-server-generic-unix-3.6.9.tar.xz
tar -xf rabbitmq-server-generic-unix-3.6.9.tar.xz
./rabbitmq_server-3.6.9/sbin/rabbitmq-server Wait until all the plugins are loaded and hit
The shell-script quit but pkill epmd && pkill beam.smp If we "apply the patch", i.e. use
The reason I am reproducing the bug is because the |
Thank you for the updated patch! The following script is enough to demonstrate the issue: #!/bin/sh
set -e
do_things () {
sleep 20
}
trap "echo 'Got SIGINT'" INT
do_things &
wait $! If we hit Ctrl+C, the script is supposed to display I just noticed that even with Dash, the |
Here is the same small script modified with a homebrew signal handler for Dash: #!/bin/sh
set -e
do_things () {
sleep 20
}
signal_handler() {
echo "Running signal handler"
}
trap "signal_handler; exit 0" HUP TERM TSTP
trap "signal_handler; exit 130" INT
do_things &
if wait $!; then
:
else
status=$?
case "$(kill -l $status)" in
HUP|TERM|TSTP) signal_handler ;;
INT) signal_handler; exit $status ;;
esac
fi It behaves the same with Dash, Bash and FreeBSD sh. What do you think? |
I like that! I will test it on my system and change the patch later today. |
@sodre: Note that I changed the Also, before we convert the exit status to a signal name with |
The |
We will be going with the "wait" trick. However, I think the answer is simpler than the second proposed patch. Using the first patch, I added a silly If statement to look at the result of When you guys have time please verify it also works for you and that I am not getting things messed up. In particular testing it for FreeBSD would be great. #!/bin/sh
set -e
do_things () {
sleep 20
}
trap "echo 'Got SIGINT'" INT
do_things &
if wait $!; then
:
fi |
Patrick,
Just to be sure, are you asking us to try #1200?
…On Thu, Apr 27, 2017 at 4:20 AM, Patrick Sodré ***@***.***> wrote:
We will be going with the "wait" trick. However, I think the answer is
simpler than the second proposed patch. Using the first patch, I added a
silly If statement to look at the result of wait, surprisingly it works!
When you guys have time please verify it also works for you and that I am
not getting things messed up. In particular testing it for FreeBSD would be
great.
#!/bin/sh
set -e
do_things () {
sleep 20
}
trap "echo 'Got SIGINT'" INT
do_things &
if wait $!; then
:fi
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1192 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAEQqxpU678eoK96DsT1p7cuXaGhRSNks5rz_tYgaJpZM4NHAdM>
.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
|
Michael, #1200 is the answer to #1192 (comment) when you asked to rebase the patch into "stable" if I wanted the fix in 3.6. #1192 is the same exact change but based in master. What I was asking for you guys to look at is if the script in #1192 (comment) also work for you. It was mostly out of disbelief since the only change required is this "NoOp" with the I tested the script in my Ubuntu box that was failing before, and with the "NoOp" it works well! |
We have determined that Given a happy path scenario, we are thinking of forcing The unhappy paths will be a bit more complicated since we cannot use On #!/bin/sh
set -ex
do_things() {
sleep 10
}
trap "echo SIGINTing; exit 130" INT
trap "echo SIGTERMing; exit 0" TERM
trap "echo SIGHUPing; exit 0" HUP
do_things &
do_things_pid="$!"
wait $do_things_pid || true What do you think? |
/bin/sh may point to dash which has a bug with the trap calls in lines 290-291. In that case "control-c" will kill the wait command and leave rabbitmq-server still running in the background. The fix is to add a noop around the wait command. Exit with errcode 130 for a SIGINT trap. Make set -e consistent with the other scripts. Signed-off-by: Patrick Sodré <[email protected]>
@gerhard, I also fixed the beginning of the code so that the "set -e" call is consistent with the other scripts in master. This was different for the "stable" branch PR #1200 , the scripts there were called with I hope that covers all you guys need. It was awesome working on this PR, thanks for giving me the chance to contribute to it. |
On Debian-like distributions, `/bin/sh` defaults to `/bin/dash` which has a bug with signal handlers. In the case of Dash, it looks like `set -e` (set at the beginning of this script) gets precedence over signal handling. Therefore, when `wait` is interrupted, its exit code is non-zero and because of `set -e`, the script terminates immediately without running the signal handler. To work around this issue, we use `|| true` to force that statement to succeed and the signal handler to properly execute. Replace the use of `-e` on the shebang line by a standalone `set -e`, like other scripts. This way, the script behavior remains the same if the script is started as an argument to a shell. For instance: bash ./rabbitmq-server Bump the copyright year to 2017. Signed-off-by: Patrick Sodré <[email protected]> Fixes #1192.
Thank you @sodre for the patch! We added more comments and cherry-picked it to our |
The is something in
rabbitmq-server
that preventsdash
from honoring thetrap
calls in lines 290-291.In that cases "control-c" will kill the script but leave
epmd
andbeam
still running in the background.Changing from
dash
tobash
fixes this problem.