-
Notifications
You must be signed in to change notification settings - Fork 107
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
SIGHUP leads to SIGSEGV #188
Comments
That's a good suggestion. Do you have a backtrace perhaps? What version was this observed with? |
I am compiling from tag v2.1 |
It is reproducible 100% of the time on my machine, I'll get stacktraces |
Stacktrace:
|
logic error introduced after retaining servers upon config reloading, please test to confirm it fixes your issue. |
Thanks for quick fix, I'll check it. Nevertheless, signal handling should be reduced to setting a flag, having anything else there is just asking for problems EDIT: or use things like |
It fixed a given issue, where single SIGHUP was killing relay 100% of the time. Sending signal continue to be unsafe. Here is small python script: #!/usr/bin/pyth
import os, sys, signal
pid = int(sys.argv[1])
count = 1
while True:
print count
os.kill(pid, signal.SIGHUP)
count = count+1 Call it: /tmp/smash.py $(pgrep carbon-c-relay) Tail of the output:
Stacktrace:
|
@redbaron can you check if the same stuff happens if my commit (in my fork) is applied? |
Isn't this just a race that's because of SIGHUP spamming? e.g. would unsetting the handler while we reload do the right thing? |
@Civil , I'll check, looks sane, few notes straight away:
EDIT:
|
In stack trace there is only one |
@redbaron fixed for the reload handler, will make the same stuff for other handlers tomorrow (if Fabian won't do that by himself). |
I'm also not really sure that exit_handler should be that complex. Just set "exit" to, for example, signal name and perform exit, ignoring other signals. @grobian he's actually right. I remember getting a lot of errors some time ago also related to sighup handling. It might also be related and anyway that's sort of a best practice. |
Hook the hup_handler on a trigger after receiving SIGHUP so we don't have to unset any signals, and can deal with receiving multiple SIGHUPs without causing race conditions in the code. Continuation of issue #188.
I already had a commit in progress, it sorts the somewhat artificial HUP-bombing |
@grobian look at my last stacktrace, problem appeared in Looking at commit 5a453a7 , |
huphandler re-opens streams, might be a race in there still, because the pointer gets unset |
added short sleep to mitigate this race. |
@grobian is there any particular reason why you still want to write to stdout while in signal handler? @redbaron is right about possible error's that'll be cause by possible calls to other functions from the handler. So the bug will never be properly fixed, until you'll make the handlers only to set appropriate flags. P.S. And also why not to use sig_atomic_t? It's in C89 standard so it's portable enough. |
and
I thought I used write, but it appears I use the stream-based variants, so indeed an AS race can occur. |
@grobian my point is that it seems to be there is no lose in functionality if you'll make 2 lines signal handlers functions and move all logout/logerr to appropriate functions that'll be called in the code. That'll close this topic once and for all and you'll always will be sure that signal handling doesn't have any bugs. |
yes, as my previous comment said, that's the only way ;) |
In order to be AS-Safe, just set a pending flag on receiving a signal which the main loop handles. This should avoid any race condition that can take place by deferring into MT-Safe land. This should fix the issue #188 at last.
Idling carbon-c-relay with no incoming traffic crashes with
SIGSEGV
when SIGHUP is sent.Using config:
I noticed that whole handling logic is done right inside in handler. realistically it can never be done right, ther would always be unexpected race conditions, non-reetrant functions called etc, simply because signal handler can be called in the middle of any function, even deep down in glibc.
What signal handlers should do is set global flag and then exit. main loop in a program should check for flag and invoke actual handling logic.More details on recommended practices of signal handling can be found here:
https://www.gnu.org/software/libc/manual/html_node/Nonreentrancy.html#Nonreentrancy
The text was updated successfully, but these errors were encountered: