-
Notifications
You must be signed in to change notification settings - Fork 3
ADBM-2801: Disable logging in signal handlers #96
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
|
Why not to add blocking of signals in signal handler? |
They're already blocked. The issue occurs when logging is happening somewhere else, and then a signal occurs, trying to do logging again. We don't need signals within signals to achieve this. |
Do I understand right, that removing the FUNCTION_LOG_ lines is enough to fix the deadlock? Looks like it's unsafe in not release builds. Because it contains Also it read and writes multiple non-atomic global variables. |
|
Oh, I see the problem will be here in this case: Lines 109 to 113 in 3b68e3c
|
No, it's not enough, there's more logging happening in
We can guarantee that the asserts will never fire in this case (all the parameters are hardcoded after all), and FUNCTION_TEST macros don't actually log anything, they simply save parameters into internal stacktrace. Also, this bug is rare and only really occurs if
We do not have concurrent access here, so it's fine. The signal handler interrupts the main thread of execution, so there is no threat of data races. The only issue is that interrupts can happen while the thread is holding a lock or while the logging variables are in an inconsistent state. |
Disable logging in signal handlers
Currently pgbackrest allows logging in signal handler exitOnSignal in exit.c.
Logging uses various locking operations (like gmtime) and also static internal
state, so if the signal occurs during logging, and then the signal handler
tries to log something else, this can lead to deadlocks and undefined
behavior.
Instead disable all logging inside signal handlers, since it does not contain
crucial info anyway. Tests are not added since there doesn't seem to be a
simple way to check the logs of a process that already exited.