Repository navigation
fix(disk): do not divide by zero on a filesystem with no capacity - #1062
Merged
Merged
Conversation
The used percentage is only computed when `df` reports a block count, so a filesystem with zero total blocks is listed at 0% instead of raising DivisionByZeroError. That is an Error, not a RuntimeException, so nothing in Os::getDiskData() caught it and the whole monitoring page and /api/v1/diskdata answered 500. busybox df lists such filesystems — an nsfs mount from snapd is enough — coreutils only with -a. Used is clamped at zero as well, so a filesystem reporting more available than total no longer produces a negative size and percentage. Assisted-by: ClaudeCode:claude-opus-5 Signed-off-by: Frank Karlitschek <karlitschek@users.noreply.github.com>
kesselb
force-pushed
the
fix/disk-info-zero-capacity
branch
from
August 2, 2026 21:08
306f663 to
b89f28f
Compare
kesselb
approved these changes
Aug 2, 2026
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)