Skip to content

internal/exec/stages/disks: fix file descriptor leak in blockDevMounted - #2289

Open
vishnu2ko5 wants to merge 1 commit into
coreos:mainfrom
vishnu2ko5:fix-partitions-proc-mounts-fd-leak
Open

internal/exec/stages/disks: fix file descriptor leak in blockDevMounted#2289
vishnu2ko5 wants to merge 1 commit into
coreos:mainfrom
vishnu2ko5:fix-partitions-proc-mounts-fd-leak

Conversation

@vishnu2ko5

Copy link
Copy Markdown

What this PR does / why we need it:
This fixes a file descriptor leak in the blockDevMounted function within the disk stages.

Previously, os.Open("/proc/mounts") was called without a corresponding Close(). Since blockDevMounted is executed (via blockDevInUse) for every partition and every block device during the storage initialization stage, this leak could quickly exhaust the process's open file descriptor limit during early-boot provisioning on systems with many partitions or devices.

This PR adds the missing defer mounts.Close() immediately after the file is successfully opened to ensure the file descriptor is released safely on all exit paths.

Fixes:
(Add the related issue number here if you opened an issue for this, e.g., Fixes #XYZ)

Special notes for your reviewer:

  • Verified that mounts.Close() executes correctly regardless of whether the bufio.Scanner completes entirely or returns early when a matching block device is found.

This fixes a file descriptor leak in blockDevMounted where the
file was opened but never closed.
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f2f865de-cb1e-4b7b-af31-0c093dfb5234

📥 Commits

Reviewing files that changed from the base of the PR and between 5300eed and b27e631.

📒 Files selected for processing (1)
  • internal/exec/stages/disks/partitions.go

Included review availability: Your plan includes up to 4 reviews per rolling hour; 3 remain after this review.

📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (3)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Include the required Apache 2.0 license header at the top of every Go source file.
Use the project's import ordering in Go files: standard library imports, blank line, project packages, blank line, then external dependencies.
Follow the project's Go naming conventions: exported identifiers use PascalCase, unexported identifiers use camelCase, and filenames use snake_case.

Files:

  • internal/exec/stages/disks/partitions.go
internal/exec/stages/{fetch-offline,fetch,disks,mount,files,umount}/**

📄 CodeRabbit inference engine (AGENTS.md)

Treat the execution stage order as fixed (fetch-offline, fetch, disks, mount, files, umount) because external projects hardcode this list.

Files:

  • internal/exec/stages/disks/partitions.go
internal/exec/stages/**

⚙️ CodeRabbit configuration file

internal/exec/stages/**: Execution stages are fixed (fetch-offline, fetch, disks, mount, files, umount). External projects hardcode this list. Do not add or remove stages. Config must be declarative -- describe desired state, not actions.

Files:

  • internal/exec/stages/disks/partitions.go
🔇 Additional comments (1)
internal/exec/stages/disks/partitions.go (1)

367-367: LGTM!


📝 Walkthrough

Walkthrough

The change adds deferred closure for the /proc/mounts file descriptor in blockDevMounted after a successful open.

Changes

Mount check cleanup

Layer / File(s) Summary
Defer mount table closure
internal/exec/stages/disks/partitions.go
blockDevMounted now defers closing /proc/mounts after opening it successfully.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to b27e6

This localized change releases the opened mount table file descriptor on all exit paths; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: chewi

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required subsystem prefix, lowercase imperative description, and has no trailing period.
Description check ✅ Passed The description clearly explains the file descriptor leak and the added deferred close in blockDevMounted.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Commit Message Convention ✅ Passed The PR has one non-merge commit, titled “internal/exec/stages/disks: close /proc/mounts after reading”; its subsystem, lowercase imperative description, and no period conform.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant