-
Notifications
You must be signed in to change notification settings - Fork 61
refactor: flush after calling write_all #3614
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
refactor: flush after calling write_all #3614
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
a86aac7
to
94364d2
Compare
Robot Results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks alright, some flush
es could maybe be sync
s, but I'm not sure if it's necessary either way, so approving.
@@ -415,6 +415,7 @@ async fn save_chunks_to_file_at( | |||
while let Some(bytes) = response.chunk().await? { | |||
writer.write_all(&bytes)?; | |||
} | |||
writer.flush()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this is an example where there's no functional change, because flush
on a File
is a noop, but still it's probably good to have for consistency or if somebody added a buffer and forgot to add a flush
call.
If we actually want to ensure that all writes reach the file, I think sync_data
or sync_all
might be better here.
@@ -137,6 +137,7 @@ impl CommonMosquittoConfig { | |||
|
|||
self.internal_listener.write(writer).await?; | |||
self.external_listener.write(writer).await?; | |||
writer.flush().await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: if the caller calls serialize
multiple times, then adding flush
here means some of the flushes will be redundant. The point is to flush the writer before it's dropped, so the caller should probably do it either way, but keeping it here is also fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
Signed-off-by: James Rhodes <[email protected]>
3a96e3c
to
e108a93
Compare
Proposed changes
Improve the file handling by:
BufWriter
to improve file performancefs::write(...)
instead of manually opening a fileThere are probably many cases here where it's not strictly necessary to do a flush (anywhere where we close a file before we rely on the data being persisted), but there are definitely quite a few cases where we this assumption doesn't hold for us.
Types of changes
Paste Link to the issue
Checklist
just prepare-dev
once)just format
as mentioned in CODING_GUIDELINESjust check
as mentioned in CODING_GUIDELINESFurther comments