-
Notifications
You must be signed in to change notification settings - Fork 187
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
fix: use a tmp file and rename to prevent a possible race condition #10693
Conversation
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
@jvillafanez pls dont forget to add a changelog 😃 |
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 good to me in general. Just a question and some nitpicks.
@jp it would be great if all open issues get fixed so this could go into v7 |
96ed740
to
f3d91f8
Compare
code should be ready now, assuming the tests pass |
Quality Gate passedIssues Measures |
fix: use a tmp file and rename to prevent a possible race condition
Description
Use a temporary file and then rename in order to prevent a race condition. This should help to prevent getting thumbnails with 0 byte content or with partial content.
According to the documentation, the won't be name collisions in the FS with the temporary files, so every thumbnail will be written into a unique file before trying to rename it to the final file (0 byte or partial content shouldn't happen).
NOTE: The previous
os.Create
call creates a file with 0666 permissions. The newos.CreateTemp
creates the file with 0600 permissions, so the new thumbnails will have different permissions on the FS. This shouldn't cause problems though.Related Issue
#10684
Motivation and Context
This increases the stability of the system by preventing the error from happening.
How Has This Been Tested?
Basic case has been tested manually to ensure the code doesn't break anything.
Error reproduction is very difficult because it's a race condition, but the error message should clarify what's happening.
Screenshots (if appropriate):
Types of changes
Checklist: