Skip to content

Commit 4a013be

Browse files
committed
fix(serve): guard against None request_router in update_deployment_config
When AsyncioRouter.update_deployment_config() is called before the request_router has been lazily initialised (e.g. request_router_class is None, or the first config update arrives before any replica is assigned), the self.request_router property returns None. The previous code unconditionally evaluated: len(self.request_router.curr_replicas) which raises AttributeError: 'NoneType' object has no attribute 'curr_replicas'. Fix: cache the property result in a local variable and fall back to 0 when it is None. Zero is semantically correct because no replicas are active at that point, so MetricsManager should not trigger a scaled-to-zero optimised push. Signed-off-by: chenshi5012 <chenshi5012@163.com>
1 parent 35629a8 commit 4a013be

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

python/ray/serve/_private/router.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,15 @@ def update_deployment_config(self, deployment_config: DeploymentConfig):
796796
max_backoff_s=self._max_backoff_s,
797797
)
798798

799+
# Guard against the case where request_router is None (e.g., when
800+
# request_router_class is None and lazy initialization has not yet
801+
# occurred). In that scenario there are no active replicas yet, so
802+
# passing 0 is the correct and safe value.
803+
_router = self.request_router
804+
curr_num_replicas = len(_router.curr_replicas) if _router is not None else 0
799805
self._metrics_manager.update_deployment_config(
800806
deployment_config,
801-
curr_num_replicas=len(self.request_router.curr_replicas),
807+
curr_num_replicas=curr_num_replicas,
802808
)
803809

804810
async def _resolve_request_arguments(

0 commit comments

Comments
 (0)