Repository navigation
Skip a corrupt utmpx entry rather than abandoning the whole read - #3643
Conversation
getSessions() treated a single entry failing its sanity check as a reason to discard the native read entirely and re-query every session through the who command. One bad record therefore cost the whole result and a fork/exec, on all eight implementations: JNA and FFM across Linux, macOS, FreeBSD and Solaris. The utmpx table is not reentrant, and synchronized only serialises OSHI's own readers. A session ending while the loop runs can hand back a partially written entry, so a corrupt record is an expected consequence of reading a table another process is mutating, not a sign the read is unusable. Skip that entry and keep the rest. The who fallback now applies only when the native read yields nothing at all, which makes it rare rather than routine. Both Linux implementations already had that shape, falling back through the systemd files first; they needed only the skip. Compiles and passes the gate; the macOS pair is the only path exercisable here, so the other six are untested on their platforms.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review. 📜 Recent review details⏰ Context from checks skipped due to timeout. (10)
🧰 Additional context used📓 Path-based instructions (3)**/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core-ffm/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{java,xml,md}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (7)📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
📚 Learning: 2026-07-30T00:35:22.638ZApplied to files:
📚 Learning: 2026-08-02T23:56:23.866ZApplied to files:
📚 Learning: 2026-08-03T00:46:14.953ZApplied to files:
📚 Learning: 2026-08-15T14:25:48.170ZApplied to files:
📚 Learning: 2026-08-15T15:43:29.296ZApplied to files:
📚 Learning: 2026-08-15T15:59:20.875ZApplied to files:
🔇 Additional comments (9)
📝 WalkthroughWalkthroughThe utmpx readers now skip corrupt or partially written records and continue scanning. The Changesutmpx session enumeration
Estimated code review effort: 2 (Simple) | ~15 minutes Merge Risk: ⚪ Minimal · up to The change skips malformed session records while preserving valid sessions and limits fallback execution to empty native reads; no actionable merge-blocking risk remains after normal checks and review. Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3643 +/- ##
============================================
- Coverage 80.01% 80.00% -0.02%
- Complexity 3902 4262 +360
============================================
Files 698 698
Lines 24348 24354 +6
Branches 4027 4033 +6
============================================
+ Hits 19482 19484 +2
- Misses 2723 2728 +5
+ Partials 2143 2142 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
getSessions()treated a single entry failing its sanity check as a reason to discard the native read entirely and re-query every session through thewhocommand:So one bad record cost the whole result and a fork/exec. Now it costs that one session:
with the
whofallback reserved for a native read that yields nothing at all.Why a corrupt entry is expected
The utmpx table is not reentrant, and
synchronizedonly serialises OSHI's own readers — it says nothing about the rest of the system. A session ending while we iterate can legitimately hand back a partially written record. That makes a bad entry a normal consequence of reading a table another process is mutating, not evidence the read is unusable.Treating it as fatal also had the perverse effect of making the rarer path the more expensive one: the response to a transient glitch was to spawn a process and re-read everything.
Scope
Applied identically to all eight implementations — JNA and FFM across Linux, macOS, FreeBSD and Solaris. Both Linux implementations already fell back only when the list came back empty (trying the systemd files first), so they needed only the skip half; the other six also gained the empty-list guard.
Testing
Full gate green: 1338 / 119 / 100 / 30 tests, checkstyle 0 violations, forbiddenapis, javadoc, and the error-prone/NullAway profile.
Only the macOS pair is exercisable on my hardware, so the Linux, FreeBSD and Solaris paths are compiled but untested on their platforms. The change is uniform across all eight, which is the main thing keeping that risk low.
What this does and does not fix
It makes the
whofallback rare rather than routine, which shrinks exposure toExecutingCommandon platforms where that path has looked fragile. It is not a proven fix for any specific crash — I have not confirmed which call inside the fallback was at fault, only that the fallback was being reached far more often than it should have been.Summary by CodeRabbit
Bug Fixes
whofallback is used only when no sessions are successfully read or a native read error occurs.Documentation