You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After we have chased down a bug in our multiprocess application, which caused messages passed between processes to get lost sometimes, I would like to suggest including a small hint in the Rust documentation of BufReader. Maybe a lint implementation for clippy also would be possible.
Background
The messages got (sometimes partly) lost, because I repeatedly created a BufReader instance on the same ChildStdout reference for every line I wanted to read off the stream. This instance got then dropped at the end of the scope. Retroperspective this was not a wise decision in my implementation and I understand that this can cause parts of stream data to get lost when the BufReader instance gets dropped.
But when implementing it I did not think of such a possibility and finding the source of this bug was quite difficult. It ended up searching the libstd source, after having found out that a crude self implementation of read_line() somehow fixed the bug. Only this brought up the idea, that the buffering of BufReader could be the cause of our issues.
Code
The issue can be reproduced by the following simple application and one file input.log with some lines of text in the execution directory. The read lines are written for comparison into output.log.
To decrease the chance for others repeating the same mistake, I would suggest a short hint in the documentation of BufReader, that creating multiple instances on a referenced stream (especially in some sort of loop) can cause data loss.
Maybe it might even be possible to implement a clippy lint to fetch such a pitfall.
The text was updated successfully, but these errors were encountered:
jonas-schievink
added
the
A-docs
Area: documentation for any part of the project, including the compiler, standard library, and tools
label
Jan 27, 2019
czipperz
added a commit
to czipperz/rust
that referenced
this issue
Mar 28, 2019
Introduction
After we have chased down a bug in our multiprocess application, which caused messages passed between processes to get lost sometimes, I would like to suggest including a small hint in the Rust documentation of
BufReader
. Maybe a lint implementation for clippy also would be possible.Background
The messages got (sometimes partly) lost, because I repeatedly created a
BufReader
instance on the sameChildStdout
reference for every line I wanted to read off the stream. This instance got then dropped at the end of the scope. Retroperspective this was not a wise decision in my implementation and I understand that this can cause parts of stream data to get lost when theBufReader
instance gets dropped.But when implementing it I did not think of such a possibility and finding the source of this bug was quite difficult. It ended up searching the libstd source, after having found out that a crude self implementation of
read_line()
somehow fixed the bug. Only this brought up the idea, that the buffering ofBufReader
could be the cause of our issues.Code
The issue can be reproduced by the following simple application and one file
input.log
with some lines of text in the execution directory. The read lines are written for comparison intooutput.log
.Suggestion
To decrease the chance for others repeating the same mistake, I would suggest a short hint in the documentation of
BufReader
, that creating multiple instances on a referenced stream (especially in some sort of loop) can cause data loss.Maybe it might even be possible to implement a clippy lint to fetch such a pitfall.
Reference
The related users topic can be found here.
The text was updated successfully, but these errors were encountered: