You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[PROF-12853] Catch panics inside wrap_with_ffi_result and wrap_with_void_ffi_result (#1334)
[PROF-12853] Catch panics inside `wrap_with_ffi_result` and `wrap_with_void_ffi_result`
**What does this PR do?**
This PR updates the `wrap_with_ffi_result` and
`wrap_with_void_ffi_result` macros to catch any panics that happen
inside them, returning them as errors.
The error handling is made in such a way (see `handle_panic_error`
for details) that it should be able to report back an error even if we
fail to do any allocations.
Important note: Because only the macros have been changed, and
ffi APIs that don't use the macros are of course not affected and
can still trigger panics. If we like this approach, I'll follow-up
with a separate PR to update other APIs to use the new macros.
**Motivation:**
In <https://docs.google.com/document/d/1weMu9P03KKhPQ-gh9BMqRrEzpa1BnnY0LaSRGJbfc7A/edit?usp=sharing>
(Datadog-only link, sorry!) we saw `ddog_prof_Exporter_send`
crashing due to what can be summed up as
`ddog_prof_Exporter_send` (report a profile) ->
hyper-util tries to do dns resolution in a separate thread pool ->
tokio failed to create a new thread ->
panic and we tear down the app because we can't report a profile
This is not good at all, and this PR solves this inspired by
earlier work in #815 and #1083.
**Additional Notes:**
While I don't predict that will happen very often, callers that
want to opt-out of the catch unwind behavior can still use the
`..._no_catch` variants of the macros.
The return type change in `ddog_crasht_CrashInfoBuilder_build`
does change the tag enum entries, which unfortunately is a
breaking change.
Ideas on how to work around this? This makes the following
enum entries change:
* `DDOG_CRASHT_CRASH_INFO_NEW_RESULT_OK` =>
`DDOG_CRASHT_RESULT_HANDLE_CRASH_INFO_OK_HANDLE_CRASH_INFO`
* `DDOG_CRASHT_CRASH_INFO_NEW_RESULT_ERR` =>
`DDOG_CRASHT_RESULT_HANDLE_CRASH_INFO_ERR_HANDLE_CRASH_INFO`
**How to test the change?**
This change includes test coverage. I've also separately tried to
sprinkle a few `panic!` calls manually and tested that it works as
expected.
Improve documentation around empty vec not allocating
Merge branch 'main' into ivoanjo/crash-handling-experiments
Fix off-by-one (including terminator in length)
I suspect in practice, since this is a static string, it doesn't make
a difference but let's fix it still.
Remove leftover comment
Ooops!
Clarify that failed allocation is the only expected source of an empty error
Linting fixes
Co-authored-by: taegyunkim <taegyun.kim@datadoghq.com>
Co-authored-by: ivo.anjo <ivo.anjo@datadoghq.com>
0 commit comments