Skip to content

[WIP][Profiling] Prevent panic from crossing FFI boundaries #815

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions profiling-ffi/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use ddcommon::tag::Tag;
use ddcommon_ffi::slice::{AsBytes, ByteSlice, CharSlice, Slice};
use ddcommon_ffi::{Error, MaybeError, Timespec};
use std::borrow::Cow;
use std::panic::{AssertUnwindSafe, catch_unwind};
use std::ptr::NonNull;
use std::str::FromStr;

Expand Down Expand Up @@ -200,11 +201,16 @@ pub unsafe extern "C" fn ddog_prof_Exporter_set_timeout(
exporter: Option<&mut ProfileExporter>,
timeout_ms: u64,
) -> MaybeError {
if let Some(ptr) = exporter {
ptr.set_timeout(timeout_ms);
MaybeError::None
} else {
MaybeError::Some(Error::from("Invalid argument"))
match catch_unwind(AssertUnwindSafe(|| {
if let Some(ptr) = exporter {
ptr.set_timeout(timeout_ms);
MaybeError::None
} else {
MaybeError::Some(Error::from("Invalid argument"))
}
})) {
Ok(r) => r,
Err(_) => MaybeError::Some(Error::from("oops"))
}
}

Expand Down
Loading