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: do not leak file handles from Compactor.write #25725

Merged
merged 6 commits into from
Jan 3, 2025

Conversation

davidby-influx
Copy link
Contributor

There are a number of code paths in Compactor.write which on error can lead to leaked file handles to temporary files. This, in turn, prevents the removal of the temporary files until InfluxDB is rebooted, releasing the file handles.

closes #25724

There are a number of code paths in Compactor.write which
on error can lead to leaked file handles to temporary files.
This, in turn, prevents the removal of the temporary files until
InfluxDB is rebooted, releasing the file handles.

closes #25724
devanbenz
devanbenz previously approved these changes Jan 2, 2025
Copy link

@devanbenz devanbenz left a comment

Choose a reason for hiding this comment

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

This looks good to me. Just one note about errors.Is and errors.Join expectation settings. I'm sure its fine though. I didn't notice any holes as I went through.

@@ -1064,11 +1064,11 @@ func (c *Compactor) writeNewFiles(generation, sequence int, src []string, iter K

// We've hit the max file limit and there is more to write. Create a new file
// and continue.
if err == errMaxFileExceeded || err == ErrMaxBlocksExceeded {
if errors.Is(err, errMaxFileExceeded) || errors.Is(err, ErrMaxBlocksExceeded) {
Copy link

@devanbenz devanbenz Jan 2, 2025

Choose a reason for hiding this comment

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

Not sure if it matters but since you are joining errors and then checking with errors.Is if there are multiple errors joined and errMaxFileExceed or ErrMaxBlocksExceeded is in the errors this will pass the test.

See the following example where I check for a single error. The function that returns two errors combined still passes the test.
https://goplay.tools/snippet/b_YVLCYn5-j

I'm sure thats what you were expecting but just something I noticed with errors.Is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although the original code discards file closing errors on errMaxFileExceededor or ErrMaxBlocksExceeded, behavior that using errors.Is essentially replicates because of the feature you mention above, on reflection I think we should report and abort compaction on file closing errors, which will require an additional commit to this PR.

tsdb/engine/tsm1/compact.go Outdated Show resolved Hide resolved
tsdb/engine/tsm1/compact.go Outdated Show resolved Hide resolved
tsdb/engine/tsm1/compact.go Outdated Show resolved Hide resolved
@davidby-influx davidby-influx requested a review from gwossum January 3, 2025 22:36
Copy link
Member

@gwossum gwossum left a comment

Choose a reason for hiding this comment

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

LGTM

@davidby-influx davidby-influx merged commit e974165 into master-1.x Jan 3, 2025
9 checks passed
@davidby-influx davidby-influx deleted the DSB_compactor_closer branch January 3, 2025 22:44
davidby-influx added a commit that referenced this pull request Jan 3, 2025
There are a number of code paths in Compactor.write which
on error can lead to leaked file handles to temporary files.
This, in turn, prevents the removal of the temporary files until
InfluxDB is rebooted, releasing the file handles.

closes #25724

(cherry picked from commit e974165)

closes #25739
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prevent file handle leaks from Compactor.write on errors
3 participants