Skip to content

fix(keystore): flush file before return#447

Merged
iamquang95 merged 1 commit into
mainfrom
iamquang95/keystore-fix
May 28, 2026
Merged

fix(keystore): flush file before return#447
iamquang95 merged 1 commit into
mainfrom
iamquang95/keystore-fix

Conversation

@iamquang95
Copy link
Copy Markdown
Collaborator

@iamquang95 iamquang95 commented May 27, 2026

https://docs.rs/tokio/latest/tokio/fs/struct.File.html

A file will not be closed immediately when it goes out of scope if there are any IO operations that have not yet completed. To ensure that a file is closed immediately when it is dropped, you should call flush before dropping it. Note that this does not ensure that the file has been fully written to disk; the operating system might keep the changes around in an in-memory buffer. See the sync_all method for telling the OS to write the data to disk.

@emlautarom1
Copy link
Copy Markdown
Collaborator

Are there any other similar scenarios (tests or production code) where we should flush? Let's extend the PR with those too if any.

@iamquang95
Copy link
Copy Markdown
Collaborator Author

We need to flush for tokio::fs::File::write_all only, the tokio::fs::File::write in tokio wraps a blocking call std:: fs::write so it's safe, no need to manually flush. I checked the codebase, and there is only one place use the tokio::fs::File::write_all is in the keystore

@iamquang95 iamquang95 requested a review from emlautarom1 May 28, 2026 03:49
@emlautarom1
Copy link
Copy Markdown
Collaborator

Good opportunity to expand our agent skills and include this gotcha https://github.com/NethermindEth/pluto/blob/main/.claude/skills/rust-style/SKILL.md

@iamquang95 iamquang95 merged commit df5720e into main May 28, 2026
14 checks passed
@iamquang95 iamquang95 deleted the iamquang95/keystore-fix branch May 28, 2026 16:10
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 this pull request may close these issues.

3 participants