-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
Crash on arbitrary signal that is blocked on main thread #806
Comments
I wonder if it's also worth adding the following to: curl_easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1); References: |
I think that's a good point, following the links there is also https://curl.se/libcurl/c/threadsafe.html which says:
and continues:
So by the recommendation The remaining problem is that main thread could then receive Investigating a bit further lead me to |
Thanks, @Zxey. It was only a matter of time before a use-case raised this issue with more elaborate signal handling requirements. You can certainly prepare a PR for this. Our signal handlers don't have to run in any background workers by design, but we might need to discuss/evaluate the consequences in the scenario where the handlers of a crash-backend are active. As a first step, I could imagine providing a compile-time flag only considered when But the issues mentioned in the comments are not entirely overlapping and should be handled separately or only where they interact. Specifically, we have to consider how this interacts with We currently do not control the build of |
Sorry I have been sick for the last two weeks. I also had a deeper look into the topic and came to the following insights:
This leads me to conclude that it doesn't make much sense to invest time configuring It also means there is no bug in the current transport implementation except for a vanishingly small portion of the This also answers why we never got any bugs reported where people see the The only immediate sensible action would be to require the Regarding the initial suggestion from @rhzx86: this mostly makes sense as a build-time configuration where the default should be to not mask the signals because it would also affect the thread-directed signals (like CC: @bitsandfoxes, @markushi, @Swatinem |
Description
In our application we use epoll to manage our main application loop and we also let it handle plethora of linux signals as opposed to using signal handlers. In order to handle linux signal with epoll you need to block the signal and pass it to
singalfd
which is in turn passed to epoll to check if signal is waiting to be handled. The signals need to be blocked in main thread so they do not crash our application as they are not handled the traditional way (using signal handlers).The problem arises when there is another thread running which does not have the signals blocked, because when linux kernel sends any kind of signal that is blocked to our app, it sees that the main thread has the signal blocked and thus chooses to send the signal to any thread that does not have the signal blocked and if not handled in that specific thread the whole app crashes.
When using the
curl
transport backend provided by sentry-native library, whensentry_init
is called it creates bgworker thread for sending any events tosentry.io
withlibcurl
and this thread does not have any signals blocked, meaning the linux kernel decides to send signal to that thread, crashing our app.When does the problem happen
Environment
We do not use any crash handing backend (SENTRY_BACKEND=none) yet and just use the event reporting facilities of sentry-native.
Steps To Reproduce
As providing the steps to reproduce are quite involved and harder to provide than the actual solution to this problem I think it is best to demonstrate the possible solution that can be implemented in
sentry-native
to mitigate this problem.This is a possible implementation of
sentry__thread_spawn
that would mitigate the issue described above:Workaround Steps
For anyone who runs into this issue, the workaround to the issue is the same as the solution provided above, but instead of
pthread_create()
you need to callsentry_init()
, it is basically the same solution but one level higher (you block all signals, callsentry_init()
, all threads created bysentry_init()
get the mask inherited and then you restore the original mask).Log output
Log output should not be relevant but here it is for completion.
Output
If desired, we can provide corresponding PR, fixing this issue. Would you be open to such contributions? Do you think this is a good solution to our problem and/or could it be solved in a different way?
The text was updated successfully, but these errors were encountered: