You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "lidavidm (via GitHub)" <gi...@apache.org> on 2025/12/17 21:27:37 UTC
[PR] feat(rust/ffi): catch panics at FFI boundary [arrow-adbc]
lidavidm opened a new pull request, #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819
This gives a slightly nicer experience than unconditionally crashing the entire program. As with the Go FFI scaffolding, once a driver panics, all further calls to the driver will fail. (Albeit, this is not true for exported readers. We also need our own C Data Interface export shim so we can handle things like exporting ADBC errors through the C Data Interface boundary. Currently, C++ and Go-based drivers can do this.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on code in PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819#discussion_r2648697333
##########
rust/ffi/src/driver_exporter.rs:
##########
@@ -456,29 +493,71 @@ where
}
}
+static POISON: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
+
+fn catch_panic<F: FnOnce() -> AdbcStatusCode + std::panic::UnwindSafe>(
+ error: *mut FFI_AdbcError,
+ f: F,
+) -> AdbcStatusCode {
+ check_err!(check_poison(), error);
+
+ match std::panic::catch_unwind(f) {
+ Ok(status) => status,
+ Err(panic) => {
Review Comment:
```suggestion
Err(cause) => {
```
tiniest of nits
##########
rust/ffi/src/driver_exporter.rs:
##########
@@ -207,6 +208,16 @@ macro_rules! export_driver {
}
adbc_core::constants::ADBC_STATUS_OK
}
+
+ #[allow(non_snake_case)]
+ #[no_mangle]
+ pub unsafe extern "C" fn AdbcDriverInit(
Review Comment:
why this change (L212:220)?
##########
rust/ffi/src/driver_exporter.rs:
##########
@@ -456,29 +493,71 @@ where
}
}
+static POISON: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
+
+fn catch_panic<F: FnOnce() -> AdbcStatusCode + std::panic::UnwindSafe>(
+ error: *mut FFI_AdbcError,
+ f: F,
+) -> AdbcStatusCode {
+ check_err!(check_poison(), error);
+
+ match std::panic::catch_unwind(f) {
+ Ok(status) => status,
+ Err(panic) => {
+ POISON.store(true, std::sync::atomic::Ordering::Release);
+
+ if !error.is_null() {
+ let message = if let Some(s) = panic.downcast_ref::<&str>() {
+ s.to_string()
+ } else if let Some(s) = panic.downcast_ref::<String>() {
Review Comment:
```suggestion
} else if let Some(s) = cause.downcast_ref::<String>() {
```
##########
rust/ffi/src/driver_exporter.rs:
##########
@@ -456,29 +493,71 @@ where
}
}
+static POISON: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
+
+fn catch_panic<F: FnOnce() -> AdbcStatusCode + std::panic::UnwindSafe>(
+ error: *mut FFI_AdbcError,
+ f: F,
+) -> AdbcStatusCode {
+ check_err!(check_poison(), error);
+
+ match std::panic::catch_unwind(f) {
+ Ok(status) => status,
+ Err(panic) => {
+ POISON.store(true, std::sync::atomic::Ordering::Release);
+
+ if !error.is_null() {
+ let message = if let Some(s) = panic.downcast_ref::<&str>() {
Review Comment:
```suggestion
let message = if let Some(s) = cause.downcast_ref::<&str>() {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819#issuecomment-3692212171
also CC @eitsupi if you're interested
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819#discussion_r2649502371
##########
rust/ffi/src/driver_exporter.rs:
##########
@@ -207,6 +208,16 @@ macro_rules! export_driver {
}
adbc_core::constants::ADBC_STATUS_OK
}
+
+ #[allow(non_snake_case)]
+ #[no_mangle]
+ pub unsafe extern "C" fn AdbcDriverInit(
Review Comment:
As a backstop so that the entrypoint can be found. Otherwise you have to declare it manually which is a bit inconvenient.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat!(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819#issuecomment-3695421244
https://github.com/apache/arrow-adbc/pull/3836
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat!(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819#issuecomment-3695354144
I think https://github.com/apache/arrow-adbc/commit/22b954ddb53267e7a70ca0b6521522ddc2f1f312 needs a slight fix which I'll look at
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat!(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm merged PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "eitsupi (via GitHub)" <gi...@apache.org>.
eitsupi commented on code in PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819#discussion_r2649673866
##########
rust/ffi/src/driver_exporter.rs:
##########
@@ -207,6 +208,16 @@ macro_rules! export_driver {
}
adbc_core::constants::ADBC_STATUS_OK
}
+
+ #[allow(non_snake_case)]
+ #[no_mangle]
+ pub unsafe extern "C" fn AdbcDriverInit(
+ version: std::os::raw::c_int,
+ driver: *mut std::os::raw::c_void,
+ error: *mut adbc_ffi::FFI_AdbcError,
Review Comment:
```suggestion
error: *mut $crate::FFI_AdbcError,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "eitsupi (via GitHub)" <gi...@apache.org>.
eitsupi commented on code in PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819#discussion_r2649679255
##########
rust/ffi/src/driver_exporter.rs:
##########
Review Comment:
Perhaps the documentation needs to be updated to state that "`AdbcDriverInit` is a reserved name" (no longer be able to used after this change), and perhaps the PR should be renamed to `feat(rust/ffi)! ...` to make it clear that it is a breaking change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat!(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on code in PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819#discussion_r2651335468
##########
rust/ffi/src/driver_exporter.rs:
##########
@@ -207,6 +208,16 @@ macro_rules! export_driver {
}
adbc_core::constants::ADBC_STATUS_OK
}
+
+ #[allow(non_snake_case)]
+ #[no_mangle]
+ pub unsafe extern "C" fn AdbcDriverInit(
Review Comment:
Ah, got it. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819#discussion_r2650014150
##########
rust/ffi/src/driver_exporter.rs:
##########
Review Comment:
Ah, I should update that comment...the name should be the latter (a driver should provide both)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(rust/ffi): catch panics at FFI boundary [arrow-adbc]
Posted by "eitsupi (via GitHub)" <gi...@apache.org>.
eitsupi commented on code in PR #3819:
URL: https://github.com/apache/arrow-adbc/pull/3819#discussion_r2649679255
##########
rust/ffi/src/driver_exporter.rs:
##########
Review Comment:
Perhaps the documentation needs to be updated to state that "`AdbcDriverInit` is a reserved name", and perhaps the PR should be renamed to `feat(rust/ffi)! ...` to make it clear that it is a breaking change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org