fix(disk): do not divide by zero on a filesystem with no capacity - #1062
Open
karlitschek wants to merge 1 commit into
Open
fix(disk): do not divide by zero on a filesystem with no capacity#1062karlitschek wants to merge 1 commit into
karlitschek wants to merge 1 commit into
Conversation
getDiskInfo() computed the used percentage as `used * 100 / Blocks`, using the block count straight out of `df` with no guard. A filesystem reporting zero total blocks therefore raised DivisionByZeroError. That is an Error rather than an Exception, so the `catch (RuntimeException)` around the df call did not stop it and nothing else in the chain did either: Os::getDiskData() and Os::getDiskInfo() just forward. The result was a 500 for the whole monitoring page and the whole /api/v1/diskdata response, not a single missing row. Whether it triggers depends on the df implementation. coreutils hides zero-block filesystems unless asked with -a, but busybox df lists them, so this is reachable on Alpine based images — an nsfs mount from snapd is enough. A filesystem with no capacity is now reported as 0% used, keeping the row rather than dropping it silently. The used figure is also clamped at zero, so a filesystem reporting more available than total can no longer produce a negative size and a negative percentage. Both backends carried the identical expression and both are fixed. The FreeBSD one had no disk tests at all, so it gains its first. Verified by running the new tests against the unfixed collectors: both error with DivisionByZeroError at Linux.php:229 and FreeBSD.php:209, and pass after the change. The existing expectations are untouched — a normal filesystem still reports 16.13%. Signed-off-by: Frank Karlitschek <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getDiskInfo() computed the used percentage as
used * 100 / Blocks, using the block count straight out ofdfwith no guard. A filesystem reporting zero total blocks therefore raised DivisionByZeroError.That is an Error rather than an Exception, so the
catch (RuntimeException)around the df call did not stop it and nothing else in the chain did either: Os::getDiskData() and Os::getDiskInfo() just forward. The result was a 500 for the whole monitoring page and the whole /api/v1/diskdata response, not a single missing row.Whether it triggers depends on the df implementation. coreutils hides zero-block filesystems unless asked with -a, but busybox df lists them, so this is reachable on Alpine based images — an nsfs mount from snapd is enough.
A filesystem with no capacity is now reported as 0% used, keeping the row rather than dropping it silently. The used figure is also clamped at zero, so a filesystem reporting more available than total can no longer produce a negative size and a negative percentage.
Both backends carried the identical expression and both are fixed. The FreeBSD one had no disk tests at all, so it gains its first.
Verified by running the new tests against the unfixed collectors: both error with DivisionByZeroError at Linux.php:229 and FreeBSD.php:209, and pass after the change. The existing expectations are untouched — a normal filesystem still reports 16.13%.
🤖 AI (if applicable)