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

Merged
merged 3 commits into from
Dec 3, 2024

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
Contributor

@rhafer rhafer left a 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.

@mmattel
Copy link
Contributor

mmattel commented Dec 3, 2024

@jp it would be great if all open issues get fixed so this could go into v7

@jvillafanez jvillafanez force-pushed the thumbnails_fix_fs_race branch from 96ed740 to f3d91f8 Compare December 3, 2024 10:00
@jvillafanez
Copy link
Member Author

code should be ready now, assuming the tests pass

Copy link

sonarqubecloud bot commented Dec 3, 2024

@jvillafanez jvillafanez merged commit b4f2faa into master Dec 3, 2024
4 checks passed
@jvillafanez jvillafanez deleted the thumbnails_fix_fs_race branch December 3, 2024 17:26
ownclouders pushed a commit that referenced this pull request Dec 3, 2024
fix: use a tmp file and rename to prevent a possible race condition
@micbar micbar mentioned this pull request Dec 17, 2024
12 tasks
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.

3 participants