Skip to content

[dashboard] Guard memoryConverter against null/undefined/NaN from psutil stats#64402

Open
daiping8 wants to merge 2 commits into
ray-project:masterfrom
daiping8:bug/front_memory
Open

[dashboard] Guard memoryConverter against null/undefined/NaN from psutil stats#64402
daiping8 wants to merge 2 commits into
ray-project:masterfrom
daiping8:bug/front_memory

Conversation

@daiping8

@daiping8 daiping8 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Closes #64401

Motivation

The dashboard's Worker info view is unrenderable on nodes where the reporter agent emits null for any memoryInfo field (e.g. pfaults/pageins when psutil cannot read them or raises AccessDenied). memoryConverter(null)
crashes with Cannot read properties of null (reading 'toFixed'), taking the whole Worker table down. This makes the per-node Worker view unusable for users on affected platforms/configurations.

Implementation Details

Two files changed under python/ray/dashboard/client/src/util/:

  1. converter.ts

    • Widened the parameter type to number | undefined | null to reflect that psutil as_dict() can emit null.
    • Added an upfront guard: if bytes is null, undefined, not a number, or NaN, return "-" (an explicit no-data placeholder) instead of falling through to .toFixed. The "-" placeholder is clearer in a table than an empty cell.
    • Existing byte-formatting branches and zero/negative behavior are left unchanged (zero still renders as 0.0000B); this change only adds the invalid-value guard, keeping the fix focused on the root cause.
  2. converter.unit.test.ts

    • Added an edge cases describe block with regression tests asserting that memoryConverter(null), memoryConverter(undefined), and memoryConverter(NaN)each do not throw and return"-"`.

The reporter-agent / serialization path is intentionally untouched: psutil returning null for unreadable fields is expected behavior, so the correct fix is to tolerate it at the formatting boundary rather than to coerce it earlier.

Verification

  • Unit tests pass:

    cd python/ray/dashboard/client
    CI=true ./node_modules/.bin/react-scripts test --watchAll=false src/util/converter.unit.test.ts
    # Tests: 9 passed, 9 total
  • Manual verification on a running cluster:

    • npm run build to rebuild the dashboard frontend.
    • ray start --head --dashboard-host=127.0.0.1 --dashboard-port=8265.
    • Open http://127.0.0.1:8265/#/cluster/nodes/<node-id>, open the Worker section — the page renders and no toFixed TypeError appears in the console, even when worker memoryInfo fields are null.
image

memoryConverter threw "Cannot read properties of null (reading 'toFixed')"
when the reporter agent serialized a null value for a psutil process
stat field (e.g. pfaults/pageins on platforms where psutil cannot read
them or raises AccessDenied). null < 1024 coerced to true, so the code
reached null.toFixed(4) and crashed, making the node Worker info page
fail to render.

Guard against null/undefined/NaN and return "-" (an explicit no-data
placeholder) instead of throwing. Update the type signature to reflect
that psutil as_dict() can emit null, and add regression tests for null,
undefined, and NaN.

Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
@daiping8 daiping8 requested a review from a team as a code owner June 29, 2026 01:30

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the memoryConverter utility to safely handle null, undefined, and NaN values by returning "-" instead of crashing, and adds corresponding unit tests to verify this behavior. The review feedback suggests simplifying the guard condition in memoryConverter by removing redundant checks and using Number.isNaN instead of the global isNaN. Additionally, it recommends cleaning up the unit tests by removing redundant not.toThrow assertions.

Comment thread python/ray/dashboard/client/src/util/converter.ts Outdated
Comment thread python/ray/dashboard/client/src/util/converter.unit.test.ts Outdated
Address review feedback on ray-project#64402:
- Drop redundant explicit null/undefined checks; typeof !== "number"
  already covers them.
- Use Number.isNaN instead of the global isNaN to avoid implicit coercion.
- Remove redundant not.toThrow() wrappers from the edge-case tests.

Signed-off-by: 10353800 <10353800@users.noreply.github.com>
Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[dashboard] Worker info page crashes with "Cannot read properties of null (reading 'toFixed')" when psutil memory info is null

1 participant