Xuanwo opened a new pull request, #8922:
URL: https://github.com/apache/opendal/pull/8922

   # Which issue does this PR close?
   
   None. Found during maintenance; no separate issue was filed.
   
   # Rationale for this change
   
   Async FFI operations in `bindings/dotnet` spawn futures onto an `Executor`'s 
`tokio::runtime::Runtime` without retaining an `Arc<Executor>` inside the 
spawned task:
   
   1. If a caller frees the `Operator` (and any stream handle) and `Executor` 
handles while an async operation on a custom `Executor` is still in flight, 
dropping the last `Arc<Executor>` drops `tokio::runtime::Runtime` and cancels 
pending tasks at their next yield. The FFI completion callback never runs, 
leaving the managed `TaskCompletionSource` hung and leaking its 
`AsyncStateRegistry` entry.
   2. If the last `Arc<Executor>` is dropped on a Tokio runtime thread (for 
example, inside an async FFI completion callback or when the final in-flight 
task finishes after external handles were already freed), 
`tokio::runtime::Runtime::drop` panics (`Cannot drop a runtime in a context 
where blocking is not allowed`) and aborts the host process across `extern "C"`.
   
   # What changes are included in this PR?
   
   - Update `Executor::spawn` in `bindings/dotnet/src/executor.rs` to take 
`self: &Arc<Self>` and retain an `Arc<Executor>` clone for the lifetime of the 
spawned future, covering all async operator and stream FFI operations.
   - Implement `Drop` for `Executor` using `Option<tokio::runtime::Runtime>` so 
that when `tokio::runtime::Handle::try_current().is_ok()`, shutdown uses 
`Runtime::shutdown_background()` instead of blocking `Runtime::drop`.
   - Add Rust unit and FFI regression tests in 
`bindings/dotnet/src/executor.rs` and `bindings/dotnet/src/operator.rs` 
covering in-flight task completion after external handle disposal and freeing 
handles inside a Tokio runtime / async FFI callback thread.
   
   # Are there any user-facing changes?
   
   Yes (bug fix): in-flight async operations on custom .NET `Executor`s now 
finish and invoke their completion callbacks after early `Dispose()` of 
`Operator`, stream, and `Executor` handles, and releasing the final `Executor` 
reference from a completion callback no longer aborts the host process.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - **Harness:** pi
   - **Model:** Gemini 4 Neon
   - **Effort:** High
   - **Role:** Verified the failure modes with failing Rust unit and FFI 
regression tests, implemented the `Executor` lifetime and `Drop` fix in 
`bindings/dotnet`, and ran Rust formatting, Clippy, build, and unit tests. The 
`.NET` SDK was not installed in the local environment, so managed `dotnet test` 
execution 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]

Reply via email to