internal/exec/stages/disks: fix file descriptor leak in blockDevMounted - #2289
internal/exec/stages/disks: fix file descriptor leak in blockDevMounted#2289vishnu2ko5 wants to merge 1 commit into
Conversation
This fixes a file descriptor leak in blockDevMounted where the file was opened but never closed.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
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)
Files:
internal/exec/stages/{fetch-offline,fetch,disks,mount,files,umount}/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
internal/exec/stages/**⚙️ CodeRabbit configuration file
Files:
🔇 Additional comments (1)
📝 WalkthroughWalkthroughThe change adds deferred closure for the ChangesMount check cleanup
Estimated code review effort: 1 (Trivial) | ~2 minutes Merge Risk: ⚪ Minimal · up to 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: 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
What this PR does / why we need it:
This fixes a file descriptor leak in the
blockDevMountedfunction within the disk stages.Previously,
os.Open("/proc/mounts")was called without a correspondingClose(). SinceblockDevMountedis executed (viablockDevInUse) 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:
mounts.Close()executes correctly regardless of whether thebufio.Scannercompletes entirely or returns early when a matching block device is found.