Skip to content

fix: temporary file leak in atomic_write_file #17505

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 1 commit into from
Jul 21, 2025

Conversation

anim001k
Copy link
Contributor

Description

Fixed a logical error in the atomic_write_file function that caused temporary files to remain on disk when write_fn failed. The function now properly cleans up temporary files before returning errors, preventing file system pollution.

Changes

  • Replaced map_err chain with match statement for proper error handling
  • Added temporary file cleanup on write_fn failure
  • Improved code comments for better maintainability

Problem

The original code would leave .tmp files on disk when write_fn returned an error, leading to:

  • Resource leaks
  • File system clutter
  • Potential confusion for users

Solution

Now when write_fn fails, the function:

  1. Removes the temporary file
  2. Returns the original error wrapped in FsPathError::Write

@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Jul 19, 2025
@anim001k anim001k marked this pull request as ready for review July 19, 2025 14:19
@anim001k anim001k requested a review from onbjerg as a code owner July 19, 2025 14:19
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

I see, that makes sense

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Jul 21, 2025
@mattsse mattsse added this pull request to the merge queue Jul 21, 2025
Merged via the queue into paradigmxyz:main with commit a49fef8 Jul 21, 2025
42 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants