Skip to content

Commit 5d95def

Browse files
fix dynamic config
Signed-off-by: Rui Zhang <[email protected]>
1 parent 55ae3da commit 5d95def

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/vllm_router/service_discovery.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def __init__(
226226
self.engines_id = [str(uuid.uuid4()) for i in range(0, len(urls))]
227227
self.added_timestamp = int(time.time())
228228
self.unhealthy_endpoint_hashes = []
229+
self._running = True
229230
if static_backend_health_checks:
230231
self.start_health_check_task()
231232
self.prefill_model_labels = prefill_model_labels
@@ -250,10 +251,10 @@ def get_unhealthy_endpoint_hashes(self) -> list[str]:
250251
return unhealthy_endpoints
251252

252253
async def check_model_health(self):
253-
while True:
254+
while self._running:
254255
try:
255256
self.unhealthy_endpoint_hashes = self.get_unhealthy_endpoint_hashes()
256-
time.sleep(60)
257+
await asyncio.sleep(60) # Use async sleep instead of time.sleep
257258
except Exception as e:
258259
logger.error(e)
259260

@@ -340,6 +341,17 @@ async def initialize_client_sessions(self) -> None:
340341
timeout=aiohttp.ClientTimeout(total=None),
341342
)
342343

344+
def close(self):
345+
"""
346+
Close the service discovery module and clean up health check resources.
347+
"""
348+
self._running = False
349+
if hasattr(self, "loop") and self.loop is not None:
350+
self.loop.call_soon_threadsafe(self.loop.stop)
351+
if hasattr(self, "thread") and self.thread is not None:
352+
self.thread.join(timeout=5.0)
353+
self.loop.close()
354+
343355

344356
class K8sPodIPServiceDiscovery(ServiceDiscovery):
345357
def __init__(

0 commit comments

Comments
 (0)