Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: FuturesAsyncWriter does not properly close/shutdown the writer #4926

Closed
1 task
kyle-mccarthy opened this issue Jul 26, 2024 · 1 comment · Fixed by #4928
Closed
1 task

bug: FuturesAsyncWriter does not properly close/shutdown the writer #4926

kyle-mccarthy opened this issue Jul 26, 2024 · 1 comment · Fixed by #4928
Labels
documentation Improvements or additions to documentation

Comments

@kyle-mccarthy
Copy link

kyle-mccarthy commented Jul 26, 2024

Describe the bug

FuturesAsyncWriter does not properly close the underlying writer, causing the write to silently fail. This is contrary to the documentation "FuturesAsyncWriters are automatically closed when they go out of scope."1.

Steps to Reproduce

Minimal Reproducible Example

Cargo.toml

[package]
name = "repro"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.39", features = ["full"] }
opendal = "0.47"
tokio-util = { version = "0.7", features = ["compat"] }

main.rs

use opendal::{services::Memory, Operator};
use tokio::io::AsyncWriteExt;
use tokio_util::compat::FuturesAsyncWriteCompatExt;

#[tokio::main]
async fn main() {
    let operator = Operator::new(Memory::default()).unwrap().finish();

    let mut reader: &[u8] = b"hello";
    let mut writer = operator
        .writer("test")
        .await
        .unwrap()
        .into_futures_async_write()
        .compat_write();

    tokio::io::copy(&mut reader, &mut writer).await.unwrap();

    // writer.shutdown().await.unwrap(); <-- uncomment to make it work

    operator.stat("test").await.unwrap(); // panics
}

Expected Behavior

FuturesAsyncWriters should work according to the documentation.

Additional Context

Note that explicitly dropping the writer (i.e., drop(writer);) does not fix the problem, close or shutdown has to be called.

No response

Are you willing to submit a PR to fix this bug?

  • Yes, I would like to submit a PR.

Footnotes

  1. https://github.com/apache/opendal/blob/f859bcea093678503b3150a0690eda7fae5f8061/core/src/types/write/writer.rs#L189

@kyle-mccarthy kyle-mccarthy added the bug Something isn't working label Jul 26, 2024
@Xuanwo
Copy link
Member

Xuanwo commented Jul 26, 2024

Hi, thanks a lot for raising this. The comments for FuturesAsyncWriter are wrong. It's required for FuturesAsyncWriter to call shutdown(). I will fix the comment.

@Xuanwo Xuanwo added documentation Improvements or additions to documentation and removed bug Something isn't working labels Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants