Skip to content

BufWriter not flushed #586

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

Closed
mtthw-meyer opened this issue Nov 25, 2019 · 2 comments · Fixed by #588
Closed

BufWriter not flushed #586

mtthw-meyer opened this issue Nov 25, 2019 · 2 comments · Fixed by #588

Comments

@mtthw-meyer
Copy link

mtthw-meyer commented Nov 25, 2019

If you run the attached code, connect a client, and then terminate it the time stamp is not flushed to disk (as expected?). Adding an explicit call to flush() fixed it but seems like it should not be necessary.

https://gist.github.com/mtthw-meyer/34d85197e01d686dacca5cf1cd6b28b3

@yoshuawuyts
Copy link
Contributor

yoshuawuyts commented Nov 25, 2019

@mtthw-meyer Thanks for reporting! Before we proceed, could I ask you to upload the code to github or put it in a gist? I'd rather not unzip files locally. Thanks!

@withoutboats
Copy link

I was just about to file an issue about the documentation being wrong. For now (until async destructors are possible) probably the best thing would be to change the documentation, which is currently inaccurate.

The docs state:

When the BufWriter is dropped, the contents of its buffer will be written out. However, any errors that happen in the process of flushing the buffer when the writer is dropped will be ignored. Code that wishes to handle such errors must manually call flush before the writer is dropped.

This is true of std's BufWriter type, but not of async-std's type. async-std's type does nothing on Drop, and you have to explicitly call flush to flush it. This is not surprising: there's no way to yield from async operations in destructors, so it would have to spawn a new task or block this thread in order to implement this behavior.

The documentation should be changed to clarify that this type does nothing on Drop and users must call flush. For now.

The docs also contain this line:

This type is an async version of std::io::BufReader.

This is definitely a typo and should instead refer to std::io::BufWriter.

@ghost ghost closed this as completed in #588 Nov 26, 2019
jimblandy added a commit to jimblandy/async-std that referenced this issue Aug 30, 2020
This was partially fixed in async-rs#586, but there's another sentence later that makes
the same claim.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants