Repository navigation
Fix resource leaks and flaky test in PrivilegedUtil - #3119
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
🔇 Additional comments (2)
📝 WalkthroughWalkthroughUpdated changelog; optimized Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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 |
- Wrap process stdout/stderr streams in try-with-resources in readAllBytesPrivileged() to fix CID 1670515 and CID 1670513 - Hoist FileSystems.getDefault() outside the loop in isFileAllowed() to fix CID 1670514 (FileSystem obtained once, not per iteration) - In testGetPrefixConfigured(), call clearCaches() after GlobalConfig.set() so the memoized prefix supplier is always re-evaluated against the updated config, preventing a race where parallel test classes could prime the supplier before the config value is set
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3119 +/- ##
==========================================
+ Coverage 66.53% 67.40% +0.87%
==========================================
Files 37 37
Lines 2023 2025 +2
Branches 336 336
==========================================
+ Hits 1346 1365 +19
+ Misses 562 545 -17
Partials 115 115 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes three Coverity-reported resource leaks in PrivilegedUtil and a race-condition-driven flaky unit test.
Resource leaks (Coverity)
CID 1670515 & CID 1670513:
readAllBytesPrivileged()p.getInputStream()andp.getErrorStream()were not explicitly closed. Wrapped both in a single try-with-resources block so they are closed beforedestroyProcess()runs in the outer finally.CID 1670514:
isFileAllowed()FileSystems.getDefault() was called on every loop iteration, producing a new FileSystem reference each time that Coverity false-positive flagged as unclosed. Pulled the call outside the loop into a local variable. The default FileSystem must never be closed (it is the JVM singleton), but this change also avoids the redundant repeated calls.
Flaky test
testGetPrefixConfiguredintermittently failed with the memoized prefix supplier returning""instead of"sudo -n". The@BeforeEachsetup calledclearCaches()before the config was set, leaving a window where another test class running in parallel could callgetPrefix()and prime the new supplier with an empty config beforeGlobalConfig.set()ran in this test. Fixed by callingclearCaches()immediately afterGlobalConfig.set(), ensuring the supplier is always evaluated against the updated config value.Fixes #3118
Summary by CodeRabbit
Bug Fixes
Documentation
Tests