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

fix: use a tmp file and rename to prevent a possible race condition #10693

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

Conversation

jvillafanez
Copy link
Member

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 new os.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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

@jvillafanez jvillafanez self-assigned this Nov 29, 2024
Copy link

update-docs bot commented Nov 29, 2024

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.

@mmattel
Copy link
Contributor

mmattel commented Nov 29, 2024

@jvillafanez pls dont forget to add a changelog 😃

@mmattel mmattel requested a review from kobergj November 29, 2024 14:24
Copy link

sonarcloud bot commented Nov 29, 2024

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.

2 participants