Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: file deletion called twice and ignoring errors with FileSystem storage type #35905

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

Merged
merged 49 commits into from
May 20, 2025

Conversation

cardoso
Copy link
Member

@cardoso cardoso commented Apr 29, 2025

Proposed changes (including videos or screenshots)

Removes the call to fs.stat to check if the file existed and is a file (using isFile()) before attempting to delete it. This was done asynchronously and, if the file existed and was a file, it would then call fs.unlink to delete it.

Instead, the code now directly attempts to delete the file using unlink(path). If the file does not exist (ENOENT), the error is safely ignored.

This change also helps prevent race conditions where the file could be deleted between the stat and unlink calls.

Also fixes the delete method being called twice.

Issue(s)

https://rocketchat.atlassian.net/browse/SUP-745

Steps to test or reproduce

Further comments

@cardoso cardoso added this to the 7.7.0 milestone Apr 29, 2025
Copy link
Contributor

dionisio-bot bot commented Apr 29, 2025

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

Copy link

changeset-bot bot commented Apr 29, 2025

🦋 Changeset detected

Latest commit: 41b1d9c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/freeswitch Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/license Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/instance-status Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

kodus-ai bot commented Apr 29, 2025

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

Copy link

codecov bot commented Apr 29, 2025

Codecov Report

Attention: Patch coverage is 91.11111% with 4 lines in your changes missing coverage. Please review.

Project coverage is 64.71%. Comparing base (aadc795) to head (41b1d9c).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #35905      +/-   ##
===========================================
- Coverage    64.73%   64.71%   -0.02%     
===========================================
  Files         3106     3107       +1     
  Lines        92877    93094     +217     
  Branches     17675    17775     +100     
===========================================
+ Hits         60127    60250     +123     
- Misses       29964    30056      +92     
- Partials      2786     2788       +2     
Flag Coverage Δ
e2e 58.38% <ø> (-0.01%) ⬇️
unit 71.49% <91.11%> (-0.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

github-actions bot commented Apr 29, 2025

PR Preview Action v1.6.1

🚀 View preview at
https://RocketChat.github.io/Rocket.Chat/pr-preview/pr-35905/

Built to branch gh-pages at 2025-05-19 23:16 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copy link

kodus-ai bot commented Apr 29, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

Copy link

kodus-ai bot commented Apr 30, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

Copy link

kodus-ai bot commented May 2, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

Copy link

kodus-ai bot commented May 2, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

Copy link

kodus-ai bot commented May 2, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

Copy link

kodus-ai bot commented May 2, 2025

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

Copy link

kodus-ai bot commented May 5, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

Copy link

kodus-ai bot commented May 5, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

cardoso added 13 commits May 12, 2025 18:23
Handles potential errors during file deletion within the prune history functionality.

If file deletion fails during the prune history process, it now stores the failed files instead of deleting the message attachment in the database.

Updates tests to reflect changes to the pruning process.
Refactors the rooms.cleanHistory API endpoint to directly pass parameters to the cleanRoomHistoryMethod, removing unnecessary parameter object creation.

Removes filesOnly property from the API response as it is no longer needed.
@cardoso cardoso marked this pull request as ready for review May 17, 2025 16:07
@cardoso cardoso requested a review from a team as a code owner May 17, 2025 16:07
@debdutdeb
Copy link
Member

Does this really "fix" the issue? Or is it a better version of the old code i.e. with better logging?

I'm asking because i don't necessarily see any change that makes it actually delete things, not do I see the old code not deleting things.

Unless stat fails both times (first actual call, second i don't know why, but regardless). If so do you know why?

@cardoso
Copy link
Member Author

cardoso commented May 17, 2025

@debdutdeb there's a root cause analysis in the ticket and 3 other related tickets which were part of the issue and were merged (especially #35797 which clears the files array).

About the improvements here: the old code would call delete twice, and there are possible race conditions between stat and unlink. There's no reason to call stat since unlink will perform the same pre-conditions and throw.

Indeed there's no way to fully guarantee deletion, but now we'll see real errors if something goes wrong (except for the file not existing, which is expected in some cases like changing FileUpload_FileSystemPath apart from the double call fixed here).

Maybe this PR can be renamed.

@cardoso cardoso changed the title fix: pruning does not get rid of physical files fix: file deletion called twice and ignoring errors with FileSystem storage type May 17, 2025
@MarcosSpessatto
Copy link
Member

@debdutdeb there's a root cause analysis in the ticket and 3 other related tickets which were part of the issue and were merged (especially #35797 which clears the files array).

About the improvements here: the old code would call delete twice, and there are possible race conditions between stat and unlink. There's no reason to call stat since unlink will perform the same pre-conditions and throw.

Indeed there's no way to fully guarantee deletion, but now we'll see real errors if something goes wrong (except for the file not existing, which is expected in some cases like changing FileUpload_FileSystemPath apart from the double call fixed here).

Maybe this PR can be renamed.

I think it makes sense to rename it @cardoso, maybe a chore instead?

@cardoso
Copy link
Member Author

cardoso commented May 19, 2025

@MarcosSpessatto I updated the name already to match what's being done:

fix: pruning does not get rid of physical files -> fix: file deletion called twice and ignoring errors with FileSystem storage type

I think it's better to keep it as a fix, but I can change to chore if you prefer.

@scuciatto scuciatto added the stat: QA assured Means it has been tested and approved by a company insider label May 19, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label May 19, 2025
@kodiakhq kodiakhq bot merged commit b1e5fd0 into develop May 20, 2025
49 checks passed
@kodiakhq kodiakhq bot deleted the SUP-745-fix-pruning-ufs-local branch May 20, 2025 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants