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

If a process crashes half-way through writing a cache entry to a file cache, it will get corrupted #325

Open
itamarst opened this issue Oct 18, 2023 · 2 comments
Labels

Comments

@itamarst
Copy link
Contributor

itamarst commented Oct 18, 2023

For FileCache this may not be a problem insofar as deserializing will fail? For SeparateBodyFileCache it will be, insofar as it's just a pile-of-bytes for the data in the body file.

pip doesn't have this problem since it writes to a temporary file and then uses os.replace(). CacheControl may wish to adopt this.

@woodruffw
Copy link
Member

pip doesn't have this problem since it writes to a temporary file and then uses os.replace(). CacheControl may wish to adopt this.

Makes sense. Would you be interested in sending a patch for this? Otherwise, I'll possibly have some time to look into this in the coming weeks (but no guarantees).

@itamarst
Copy link
Contributor Author

The relevant code in pip is https://github.com/pypa/pip/blob/8a0f77c171d60344e6a3bf6e95ad5740c21575fd/src/pip/_internal/network/cache.py#L57, could probably just copy-paste the relevant utility code and integrate with the locking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants