Skip to content

fix: guard against None resource_limit in _max_throughput_from_resources#62602

Open
kuishou68 wants to merge 1 commit intoray-project:masterfrom
kuishou68:fix/issue-62601-throughput-none-guard
Open

fix: guard against None resource_limit in _max_throughput_from_resources#62602
kuishou68 wants to merge 1 commit intoray-project:masterfrom
kuishou68:fix/issue-62601-throughput-none-guard

Conversation

@kuishou68
Copy link
Copy Markdown

Closes #62601

Problem

_max_throughput_from_resources() calls getattr(resource_limits, resource_name) to get CPU/GPU/memory limits. When a resource is unconstrained, ExecutionResources stores None for that field. The division resource_limit / resource_cost_per_unit_throughput then raises:

TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

Fix

Add a resource_limit is not None guard — a None limit means the resource is unconstrained and should not bound max_throughput:

# Before
if resource_cost_per_unit_throughput > 0:
    max_throughput = min(max_throughput, resource_limit / resource_cost_per_unit_throughput)

# After
if resource_cost_per_unit_throughput > 0 and resource_limit is not None:
    max_throughput = min(max_throughput, resource_limit / resource_cost_per_unit_throughput)

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 adds a null check for resource_limit in the throughput solver to prevent a TypeError when calculating maximum throughput. The review feedback points out that a similar TypeError could occur at line 100 if resource requirements are unset, and suggests handling those cases as well as optimizing the check's placement for better efficiency.

for op in rates
)
if resource_cost_per_unit_throughput > 0:
if resource_cost_per_unit_throughput > 0 and resource_limit is not None:
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.

high

While this change correctly guards against None in resource_limit, a similar TypeError is likely to occur at line 100. If any operator in resource_requirements has a None value for a resource (which ExecutionResources uses to represent unconstrained or unset fields), the division getattr(resource_requirements[op], resource_name) / rates[op] will fail. Consider handling None values in the sum calculation as well, for example by using (getattr(...) or 0). Additionally, for better efficiency, the resource_limit is not None check could be performed before the sum calculation (lines 99-102) to avoid unnecessary computation for unconstrained resources.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 00f0a40. Configure here.

for op in rates
)
if resource_cost_per_unit_throughput > 0:
if resource_cost_per_unit_throughput > 0 and resource_limit is not None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

None guard is ineffective due to property coercion

High Severity

The resource_limit is not None guard never triggers because getattr(resource_limits, resource_name) calls the cpu/gpu/memory properties on ExecutionResources, which coerce None to 0.0 via self._cpu or 0.0. So resource_limit is always a float, never None. When a resource is truly unconstrained (_cpu is None), the property returns 0.0, and 0.0 / positive_cost yields 0.0, incorrectly capping max_throughput to zero. The fix needs to check the private _cpu/_gpu/_memory attributes or otherwise detect the unconstrained case.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 00f0a40. Configure here.

@ray-gardener ray-gardener bot added serve Ray Serve Related Issue core Issues that should be addressed in Ray Core data Ray Data-related issues community-contribution Contributed by the community labels Apr 14, 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 data Ray Data-related issues serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: TypeError crash in _max_throughput_from_resources when resource_limit is None

1 participant