Skip to content

dedup backend: Fix leaking filedescriptor#2548

Merged
BareosBot merged 4 commits intobareos:masterfrom
sebsura:dev/ssura/master/fix-fd-leak
Mar 5, 2026
Merged

dedup backend: Fix leaking filedescriptor#2548
BareosBot merged 4 commits intobareos:masterfrom
sebsura:dev/ssura/master/fix-fd-leak

Conversation

@sebsura
Copy link
Contributor

@sebsura sebsura commented Feb 19, 2026

Thank you for contributing to the Bareos Project!

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

If you have any questions or problems, please give a comment in the PR.

Helpful documentation and best practices

Checklist for the reviewer of the PR (will be processed by the Bareos team)

Make sure you check/merge the PR using devtools/pr-tool to have some simple automated checks run and a proper changelog record added.

General
  • Is the PR title usable as CHANGELOG entry?
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
  • Required backport PRs have been created
  • Correct milestone is set
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8d2e9a0d-c5b5-4958-a5f0-1e54afc962c5

📥 Commits

Reviewing files that changed from the base of the PR and between f1713de and b0704c6.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • core/src/stored/backends/dedupable/util.h
  • core/src/stored/backends/dedupable/volume.cc
  • core/src/stored/backends/dedupable/volume.h

📝 Walkthrough

Walkthrough

Wrap raw directory file descriptors in raii_fd: constructors, move ops, fileno() and release() made noexcept/const, operator bool() made explicit and noexcept, and fd moved to private. volume stores dird as an raii_fd and uses dird.fileno() at call sites.

Changes

Cohort / File(s) Summary
RAII wrapper
core/src/stored/backends/dedupable/util.h
Made raii_fd constructor explicit and noexcept; move ctor and move assignment marked noexcept; fileno()int fileno() const noexcept; release() marked noexcept; operator bool()explicit operator bool() const noexcept; moved fd to private; updated copyright year.
Volume implementation & header
core/src/stored/backends/dedupable/volume.h, core/src/stored/backends/dedupable/volume.cc
Replaced raw int dir-fd with raii_fd dird; OpenRelative now returns raii_fd; call sites use dird.fileno() and the explicit operator bool(); updated open/openat usages and error handling to work with wrapper; bumped copyright years.
Changelog
CHANGELOG.md
Added unreleased changelog entry referencing the dedup backend FD leak fix (PR #2548).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • pstorz

Poem

🐰 I tuck the fds in snug and tight,

Constructors promise no-throw night,
fileno peeks, explicit bool says "here",
Private burrow keeps descriptors near,
Hoppity code, neat and light.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main objective of the PR - fixing a file descriptor leak in the dedup backend by introducing RAII wrappers to prevent resource leaks.
Description check ✅ Passed The PR description follows the required template with all major sections present and checklists completed, indicating the author addressed the template requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sebsura sebsura linked an issue Feb 19, 2026 that may be closed by this pull request
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
core/src/stored/backends/dedupable/volume.cc (1)

180-187: Minor inconsistency: use !dird.ok() for consistency with other checks.

Line 182 uses dird.fileno() < 0 while all other validity checks in this file use the ok() method (e.g., lines 191, 275, 468, 480, etc.).

Suggested fix for consistency
   dird = open(path, dir_flags);
 
-  if (dird.fileno() < 0) {
+  if (!dird.ok()) {
     std::string errctx = "Cannot open '";
     errctx += path;
     errctx += "'";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/src/stored/backends/dedupable/volume.cc` around lines 180 - 187, The
check after opening the directory uses dird.fileno() < 0 which is inconsistent
with other validity checks in this file; change the condition to use !dird.ok()
(i.e., if (!dird.ok())) when testing the result of open(path, dir_flags) so it
matches the style used elsewhere (see dird, open(path, dir_flags),
dird.fileno(), dird.ok()); keep the existing error construction and throw
behavior intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@core/src/stored/backends/dedupable/volume.cc`:
- Around line 180-187: The check after opening the directory uses dird.fileno()
< 0 which is inconsistent with other validity checks in this file; change the
condition to use !dird.ok() (i.e., if (!dird.ok())) when testing the result of
open(path, dir_flags) so it matches the style used elsewhere (see dird,
open(path, dir_flags), dird.fileno(), dird.ok()); keep the existing error
construction and throw behavior intact.

Copy link
Member

@pstorz pstorz 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, please see my comment and let's sync about that.

@sebsura sebsura force-pushed the dev/ssura/master/fix-fd-leak branch from ece401b to f1713de Compare March 3, 2026 07:24
@sebsura sebsura requested a review from pstorz March 3, 2026 07:24
@pstorz pstorz changed the title Fix leaking filedescriptor on dedup backend dedup backend: Fix leaking filedescriptor Mar 4, 2026
@pstorz pstorz modified the milestone: 25.0.3 Mar 4, 2026
Copy link
Member

@pstorz pstorz 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! Only the backports are pending now.

sebsura and others added 4 commits March 5, 2026 10:23
@BareosBot BareosBot force-pushed the dev/ssura/master/fix-fd-leak branch from efbf05c to b0704c6 Compare March 5, 2026 10:23
@BareosBot BareosBot merged commit c638c80 into bareos:master Mar 5, 2026
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.

Dedupable device on NFS appliance fails to recycle purged volume

3 participants