Commit 515a0d8
[serve] Fix AttributeError when request_router is None in update_deployment_config (ray-project#63180)
## Description
`AsyncioRouter.update_deployment_config()` unconditionally evaluates
`len(self.request_router.curr_replicas)` at the end of the method.
The `request_router` property performs lazy initialisation and returns
`None` when `_request_router_class` is `None` and `_request_router`
has not yet been initialised. In that state the call raises:
```
AttributeError: 'NoneType' object has no attribute 'curr_replicas'
```
**Trigger conditions**
1. `AsyncioRouter` is constructed without a `request_router_class` (the
parameter is `Optional`), and the Controller's first long-poll config
push arrives before any replica is assigned — the lazy-init path is
never entered, so the property returns `None`.
2. A live deployment is hot-updated to remove a custom
`request_router_class`; `update_deployment_config()` overwrites
`self._request_router_class` with the new value before the guard
`if self._request_router:` is evaluated, leaving both fields `None`.
3. Race condition: the Controller pushes a new config between
construction
and the first call to `assign_request()` that would trigger lazy init.
**Fix**
Cache the property result in a local variable and fall back to `0` when
it is `None`. Zero is semantically correct: no replicas are active yet,
so `MetricsManager` should not trigger a scaled-to-zero optimised push.
```python
# before
curr_num_replicas=len(self.request_router.curr_replicas),
# after
_router = self.request_router
curr_num_replicas = len(_router.curr_replicas) if _router is not None else 0
```
## Related issues
None — this is a self-contained bug fix.
## Checks
- [x] I've signed off every commit with `Signed-off-by`
- [x] I've run `scripts/format.sh` to lint the changes in this PR
- [x] I've included any doc changes needed for this PR
Signed-off-by: chenshi5012 <chenshi5012@163.com>1 parent 4e88c8f commit 515a0d8
1 file changed
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
796 | 796 | | |
797 | 797 | | |
798 | 798 | | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
799 | 805 | | |
800 | 806 | | |
801 | | - | |
| 807 | + | |
802 | 808 | | |
803 | 809 | | |
804 | 810 | | |
| |||
0 commit comments