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

Attempt to overwrite without race condition #335

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thatch
Copy link

@thatch thatch commented May 8, 2024

As explained in #332, there was previously a small window of time where the file is deleted before its new contents get written. Because reads don't happen with the lock held, this resulted in an empty-body cache hit when it shouldn't.

Fixes #332

As explained in psf#332, there was previously a small window of time where the
file is deleted before its new contents get written.  Because reads don't
happen with the lock held, this resulted in an empty-body cache hit when it
shouldn't.

Fixes psf#332
@woodruffw woodruffw self-requested a review May 8, 2024 22:09
@woodruffw
Copy link
Member

Thanks @thatch! I'll try and give this a review in the coming days.

@thatch
Copy link
Author

thatch commented Jun 6, 2024

Any luck with testing?

@woodruffw
Copy link
Member

Any luck with testing?

Sorry for the delay -- I was out for a bit, and I'm catching up now. I'll do some testing tonight.

Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some local testing (on Linux) and didn't hit any issues with this.

I also went through the old _secure_open_write flags and confirmed that we shouldn't be missing anything important here -- the old flags should be irrelevant for our mkstemp use (since it defaults to binary mode and O_NOFOLLOW shouldn't be relevant for fresh temporary files).

As such, this LGTM! I'd like @frostming to also do a comb over it though 🙂

(I didn't test this locally on Windows, but my understanding is that os.replace is equally atomic there.)

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.

Race condition in FileCache that can result in empty body 200 response
2 participants