Skip to content

fix(events): guard events per user/session against division by zero (Infinity/InfinityB)#7810

Open
mrmeghana wants to merge 1 commit into
masterfrom
fix/events-overview-infinity-per-user-session
Open

fix(events): guard events per user/session against division by zero (Infinity/InfinityB)#7810
mrmeghana wants to merge 1 commit into
masterfrom
fix/events-overview-infinity-per-user-session

Conversation

@mrmeghana

@mrmeghana mrmeghana commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Problem

On the Events → Overview tab, when a selected period has events but zero users and zero sessions, the cards render:

  • Events Per User: Infinity
  • Events Per Session: InfinityB

Reproduced live on release-2503 (app data: totalCount: 120, totalUsersCount: 0, totalSessionCount: 0).

Root cause

Two stacked issues:

  1. Wrong division guard in getEventOverview (countly.overview.models.js). The guard returned 0 only when both numerator and denominator were 0:

    ob.totalCount === 0 && ob.totalUsersCount === 0 ? 0 : Number((ob.totalCount / ob.totalUsersCount).toFixed(1))

    So events > 0 with users/sessions = 0 computed events / 0Infinity.

  2. countlyCommon.getShortNumber doesn't handle non-finite input. Infinity >= 1e9 is true, so (Infinity/1e9).toFixed(1)"Infinity", then + "B""InfinityB". (The per-user card renders the raw value via a number slot, hence plain Infinity; the per-session card goes through getShortNumber, hence InfinityB.)

Fix

  • Guard the denominator (!ob.totalUsersCount / !ob.totalSessionCount) for the events-per-user, events-per-session, and their prev* values.
  • Add an isFinite guard to getShortNumber so no caller can ever produce InfinityB / NaNK again.

Verification

  • Finite values unchanged (12345"12.3K", etc.) — no regression.
  • Against the real live data object: per-user and per-session now return 0 instead of Infinity; verified visually on the dashboard (cards show 0 / 0).
  • ESLint clean on both files.

Events Overview showed "Infinity" / "InfinityB" when a period had events
but zero users or sessions. The existing guard only returned 0 when BOTH
the numerator and denominator were 0, so events > 0 with users/sessions = 0
produced Infinity (events / 0).

- Guard the denominator instead of requiring both operands to be zero, in
  getEventOverview (events per user, events per session, and their prev
  values).
- Harden countlyCommon.getShortNumber to return non-finite values as-is
  instead of appending a magnitude suffix (which turned Infinity into
  "InfinityB"), as defense-in-depth for all other callers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes non-finite (“Infinity” / “InfinityB”) values shown on Events → Overview when the selected period has events but zero users/sessions, by guarding divisions at the model layer and preventing short-number formatting from appending suffixes to non-finite values.

Changes:

  • Guard events-per-user/session calculations against zero (or missing) denominators in getEventOverview.
  • Add a non-finite input guard to countlyCommon.getShortNumber to avoid producing suffixed strings like InfinityB.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
frontend/express/public/javascripts/countly/countly.common.js Adds a non-finite guard in getShortNumber so formatting never produces InfinityB.
frontend/express/public/core/events/javascripts/countly.overview.models.js Fixes division guards for per-user/per-session metrics (current and previous period) to prevent Infinity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants