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
**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.
**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.
Copy file name to clipboardExpand all lines: libdd-common-ffi/src/vec.rs
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,12 @@ impl<T: Eq> Eq for Vec<T> {}
53
53
54
54
impl<T>DropforVec<T>{
55
55
fndrop(&mutself){
56
+
// A Rust Vec of size 0 [has no allocated memory](https://doc.rust-lang.org/std/vec/struct.Vec.html#guarantees):
57
+
// "In particular, if you construct a Vec with capacity 0 via Vec::new, vec![], Vec::with_capacity(0), or by calling shrink_to_fit on an empty Vec, it will not allocate memory."
58
+
// And as per https://doc.rust-lang.org/nomicon/vec/vec-dealloc.html:
59
+
// "We must not call alloc::dealloc when self.cap == 0, as in this case we haven't actually allocated any memory."
0 commit comments