Skip to content

fix(web): guard against division by zero and nil in metrics handlers - #299

Merged
thiagoesteves merged 2 commits into
mainfrom
thiagoesteves/fix-metrics-division-by-zero
Aug 14, 2026
Merged

fix(web): guard against division by zero and nil in metrics handlers#299
thiagoesteves merged 2 commits into
mainfrom
thiagoesteves/fix-metrics-division-by-zero

Conversation

@thiagoesteves

@thiagoesteves thiagoesteves commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • 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 with ArithmeticError.
  • 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.

Test plan

  • mix test apps/deployex_web/test/deployex_web/live/applications/index_test.exs --warnings-as-errors (20 tests)
  • mix format --check-formatted
  • mix credo --strict apps/deployex_web/lib/deployex_web/live/applications/index.ex

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.

Generated with Devin powered by GLM-5.2 High

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
@thiagoesteves
thiagoesteves merged commit a838401 into main Aug 14, 2026
1 check passed
@thiagoesteves
thiagoesteves deleted the thiagoesteves/fix-metrics-division-by-zero branch August 14, 2026 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant