-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix deadlock in sighandler #231
Conversation
why not use nc_snprintf instead of multi strcat() ? |
@ideal: snprintf is good, but no document said it's signal-safe, strcat is signal-safe according to this: |
There are |
@buaazp thanks for review. here is a new commit to fix this.
|
Sadly, nc_stacktrace will call loga and free too. |
Apologies for the delay. Things have been busy! Good catch @idning. Here is a list of async-safe-signals -- https://www.securecoding.cert.org/confluence/display/seccode/SIG30-C.+Call+only+asynchronous-safe+functions+within+signal+handlers. I believe nc_snprintf() should be signal safe, as it eventually calls write() which is signal safe. Agree? If the problem is with localtime() - https://github.com/twitter/twemproxy/blob/master/src%2Fnc_log.c#L139-L141, the right thing to do in my opinon is to not call this piece of code in signal handler context. How about introducing a new function log_safe() that is exactly like _log() except that it doesn't call localtime(). So instead of printing time in [] here - https://github.com/twitter/twemproxy/blob/master/src%2Fnc_log.c#L143 you could just leave it blank So, a log line like this
in signal context would look like this:
Does that sound good? |
@manjuraj xxprintf is not signal-safe because they use malloc/free, see glibc manual: all these functions is AS-Unsafe it looks that ngx implement a new printf function to avoid this:
|
sigh :( |
@idning how about repurposing/borrowing code from ngx and calling it log_vslprintf() and calling it from log_safe() |
ngx use a cached time to be used in signal handler, it's sophisticated. |
I have add test case: I create a safe_snprintf lib for this: format:
|
Great stuff @idning |
localtime()
used in_log()
is not signal-safe.see: http://man7.org/linux/man-pages/man7/signal.7.html
if nutcracker run with a lot of log(
-v 5
and heavy load) and usekill -HUP
to reopen the logfile, nutcracker will dead lock with this:this can reproduction with::
we should use signal-safe function in signal_handler.
redis has the same problem long time ago: redis/redis#213
the new logline of this patch: