Xuanwo opened a new pull request, #8930: URL: https://github.com/apache/opendal/pull/8930
# Which issue does this PR close? Part of #7608. # Rationale for this change Downstream FFI consumers such as `bindings/go` need cooperative cancellation for blocking C binding calls (for example, to propagate Go `context.Context` cancellation) without breaking the existing C ABI or introducing unsafe background tasks that could access caller buffers after an FFI call returns. # What changes are included in this PR? - **Error code (`bindings/c/src/error.rs`)**: Append `OPENDAL_CANCELLED` at the end of `opendal_code` (discriminant `13`, preserving `0..=12` unchanged) without changing `opendal-core`'s `ErrorKind`. - **Cancel token (`bindings/c/src/cancel.rs`)**: Add opaque, thread-safe `opendal_cancel_token` (`opendal_cancel_token_new`, `opendal_cancel_token_cancel`, `opendal_cancel_token_is_cancelled`, `opendal_cancel_token_free`) backed by `AtomicBool` and `tokio::sync::watch`, plus `block_on_cancellable` which polls futures in-place on the calling thread so cancelled futures are synchronously dropped before FFI return. - **Internal async handles (`bindings/c/src/*.rs`, `bindings/c/Cargo.toml`)**: Migrate internal C handles (`opendal_operator`, `opendal_reader`, `opendal_writer`, `opendal_lister`, `opendal_deleter`, `opendal_copier`) from `opendal::blocking::*` to async `opendal::*` driven by the stored `tokio::runtime::Handle`, dropping async inner handles inside the Tokio runtime context. Enable `tokio`'s `sync` feature, declare `futures` (already present in `DEPENDENCIES.rust.tsv`), and drop the unused `opendal/blocking` feature—introducing zero new crates. - **Cancellable C APIs (`bindings/c/src/*.rs`, `bindings/c/include/opendal.h`)**: Add 28 `*_with_cancel` functions (18 operator-level and 10 handle-level, all with `<= 6` parameters for `purego` compatibility). Existing C APIs keep identical signatures/ABI and delegate with a `NULL` cancel token. All non-null output pointers are zeroed/nulled on error or cancellation. Regenerate `bindings/c/include/opendal.h` with `cbindgen`. - **Tests (`bindings/c/src/cancel.rs`, `bindings/c/tests/cancel.cpp`, `bindings/c/CMakeLists.txt`)**: Add deterministic Rust unit tests proving synchronous future drop before FFI return and mid-flight cancellation through a test-only blocking layer, and add C++ ASan GTests covering token lifecycle, pre-cancelled calls, `NULL` token fallback, and concurrent cancellation with immediate buffer free. # Are there any user-facing changes? Yes. `bindings/c` adds the `opendal_cancel_token` type and lifecycle functions, `OPENDAL_CANCELLED` error code, and 28 `*_with_cancel` C APIs. Existing C APIs remain fully source- and ABI-compatible. # Breaking changes # AI Usage Statement - Harness: pi / T3 Code - Model: Gemini 4 Neon - Effort: High - Role: Implemented the `bindings/c` cancellation token, async handle migration, 28 `*_with_cancel` C APIs, regenerated `bindings/c/include/opendal.h`, and Rust/C++ tests. Local Go binding smoke testing against the built shared library was not run because `go` is not installed in the local environment and relies on CI. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
