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

ReadStream/WriteStream can lead to data races #63

Open
floren opened this issue May 4, 2021 · 0 comments
Open

ReadStream/WriteStream can lead to data races #63

floren opened this issue May 4, 2021 · 0 comments

Comments

@floren
Copy link
Contributor

floren commented May 4, 2021

If someone calls ReadStream, then proceeds to read from it slowly, then someone else calls WriteStream, the reader will start to get the new resource contents part-way through. This is because createKeyFileWithNoLock calls os.OpenFile with O_TRUNC set when updating a file, and the existing reader ends up pointing at the new data.

floren added a commit to floren/diskv that referenced this issue May 4, 2021
floren added a commit to floren/diskv that referenced this issue May 6, 2021
floren added a commit to floren/diskv that referenced this issue May 6, 2021
…after write.

This reworks the createKeyFileWithLock function (used only by
writeStreamWithLock) so it always writes to a temporary file, which
is renamed by writeStreamWithLock when complete. A deferred recover is
added to clean up the temporary file if writing fails. This essentially
deprecates the TempDir option by making all writes atomic.
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

No branches or pull requests

1 participant