diff --git a/src/changelog.rs b/src/changelog.rs index 1baac74..e3fcd66 100644 --- a/src/changelog.rs +++ b/src/changelog.rs @@ -1,6 +1,9 @@ #[allow(unused_imports)] use crate::*; +/// ## Improved +/// - Fix: change the drop of `OwnedHandle` to wait for the close request in order to +/// avoid invalid response id after closing file #[doc(hidden)] pub mod unreleased {} diff --git a/src/handle.rs b/src/handle.rs index 6f58c11..65d6441 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -27,11 +27,14 @@ impl Drop for OwnedHandle { if Arc::strong_count(handle) == 1 { // This is the last reference to the arc let id = write_end.get_id_mut(); - let _ = write_end.send_close_request(id, Cow::Borrowed(handle)); - - // Requests is already added to write buffer, so wakeup - // the `flush_task`. - self.get_auxiliary().wakeup_flush_task(); + if let Ok(response) = write_end.send_close_request(id, Cow::Borrowed(handle)) { + // Requests is already added to write buffer, so wakeup + // the `flush_task`. + self.get_auxiliary().wakeup_flush_task(); + tokio::spawn(async move { + let _ = response.wait().await; + }); + } } } }