You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "Xuanwo (via GitHub)" <gi...@apache.org> on 2025/04/16 11:14:45 UTC

Re: [PR] feat(core): impl Drop for BlockingWrapper [opendal]

Xuanwo commented on code in PR #6036:
URL: https://github.com/apache/opendal/pull/6036#discussion_r2046695592


##########
core/src/layers/blocking.rs:
##########
@@ -292,6 +292,21 @@ impl<I: oio::Write + 'static> oio::BlockingWrite for BlockingWrapper<I> {
     }
 }
 
+impl<I: oio::Write + 'static> Drop for BlockingWrapper<I> {

Review Comment:
   We don't need to add `oio::Write + 'static` here. 



##########
core/src/layers/blocking.rs:
##########
@@ -292,6 +292,21 @@ impl<I: oio::Write + 'static> oio::BlockingWrite for BlockingWrapper<I> {
     }
 }
 
+impl<I: oio::Write + 'static> Drop for BlockingWrapper<I> {
+    fn drop(&mut self) {
+        // Attempt to close the inner writer, blocking on the current handle.
+        // This might panic if called from within an existing `block_on` scope
+        // on the same runtime handle.
+        // We ignore the result because drop should not panic.
+        if let Err(err) = self.handle.block_on(self.inner.close()) {

Review Comment:
   Calling `close` in `drop` is incorrect. Instead, we should take the `inner` value and drop it within an async context.
   
   To implement this, maybe we use change `inner: I` to `inner: Option<I>` instead.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org