fix(web): guard against division by zero and nil in metrics handlers - #299
Merged
Merged
Conversation
The metrics handlers in the applications LiveView could crash with an
ArithmeticError when dividing by zero or nil:
- handle_info({:update_system_info, ...}) divided by host_info.memory_total,
which is nil | non_neg_integer() per Host.Info. A nil or 0 value crashed
the LiveView process.
- handle_info({:metrics_new_data, ...}) divided by the metric limit. A node
reporting limit: 0 crashed the LiveView process.
Add guards to both handlers so they skip the metric update when the divisor
is nil or 0, and add a fallback clause for update_system_info that still
updates host_info without computing the memory percentage.
Risk assessment:
- Impact: the applications LiveView no longer crashes when host memory info
is incomplete or a VM metric reports a zero limit
- Blast radius: deployex_web applications LiveView only; no other handlers
or apps are touched
- Regression risk: low - the guards only skip the percentage computation in
edge cases that previously crashed; normal values are unaffected
- Rollback: plain commit revert
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.
Summary
handle_info({:update_system_info, ...})divided byhost_info.memory_total, which isnil | non_neg_integer()perHost.Info. A nil or 0 value crashed the LiveView process withArithmeticError.handle_info({:metrics_new_data, ...})divided by the metric limit. A node reportinglimit: 0crashed the LiveView process.update_system_infothat still updateshost_infowithout computing the memory percentage.Test plan
mix test apps/deployex_web/test/deployex_web/live/applications/index_test.exs --warnings-as-errors(20 tests)mix format --check-formattedmix credo --strict apps/deployex_web/lib/deployex_web/live/applications/index.exRisk assessment
Generated with Devin powered by GLM-5.2 High