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

Prevent leaking file descriptor during snapshotting and provide better logging of errors #19093

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

serathius
Copy link
Member

cc @ahrtr @fuweid @ivanvc

Found case where a leaked file descriptor prevents data being deleted from disk and filling up the disk.

Would like to backport it to all v3.5 and v3.4

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 45.00000% with 11 lines in your changes missing coverage. Please review.

Project coverage is 68.79%. Comparing base (9fa35e5) to head (c504fed).
Report is 94 commits behind head on main.

Files with missing lines Patch % Lines
client/v3/snapshot/v3_snapshot.go 45.00% 7 Missing and 4 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
client/v3/snapshot/v3_snapshot.go 52.72% <45.00%> (-5.42%) ⬇️

... and 44 files with indirect coverage changes

@@            Coverage Diff             @@
##             main   #19093      +/-   ##
==========================================
- Coverage   68.85%   68.79%   -0.07%     
==========================================
  Files         420      420              
  Lines       35642    35650       +8     
==========================================
- Hits        24541    24525      -16     
- Misses       9676     9704      +28     
+ Partials     1425     1421       -4     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9fa35e5...c504fed. Read the comment docs.

@ahrtr
Copy link
Member

ahrtr commented Dec 20, 2024

We need to close all previous similar PRs, one of which is #18200

if err != nil {
return "", fmt.Errorf("could not open %s (%w)", partpath, err)
}
defer func() {
err = f.Close()
if err != nil && !errors.Is(err, os.ErrClosed) {
Copy link
Member

Choose a reason for hiding this comment

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

It works. But I think a better and more explicit way is to use sync.Once to ensure f.Close is only executed once. So that it's well aware that we need to close the file before renaming, but also need to ensure it's closed in case early return due to any error.

Copy link
Member

Choose a reason for hiding this comment

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

Checked https://pkg.go.dev/os#File.Close and the api can guarantee it can be executed only once. sync.Once is not neccesary here.

Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal, please feel free to merge this PR and backport to 3.5 and 3.4.

Copy link
Member Author

Choose a reason for hiding this comment

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

SGTM

Copy link
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

client/v3/snapshot/v3_snapshot.go Outdated Show resolved Hide resolved
@jmhbnz
Copy link
Member

jmhbnz commented Jan 16, 2025

/retest

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahrtr, fuweid, serathius

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@serathius
Copy link
Member Author

/retest

@serathius serathius merged commit 5d47d7f into etcd-io:main Jan 17, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants