Skip to content

Commit

Permalink
[Bugfix] Bind api server port before starting engine (vllm-project#8491)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin314 committed Sep 16, 2024
1 parent 2759a43 commit 47f5e03
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vllm/entrypoints/openai/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import re
import signal
import socket
import tempfile
from argparse import Namespace
from contextlib import asynccontextmanager
Expand Down Expand Up @@ -525,6 +526,9 @@ async def run_server(args, **uvicorn_kwargs) -> None:
logger.info("vLLM API server version %s", VLLM_VERSION)
logger.info("args: %s", args)

temp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
temp_socket.bind(("", args.port))

def signal_handler(*_) -> None:
# Interrupt server on sigterm while initializing
raise KeyboardInterrupt("terminated")
Expand All @@ -541,6 +545,8 @@ def signal_handler(*_) -> None:
model_config = await async_engine_client.get_model_config()
init_app_state(async_engine_client, model_config, app.state, args)

temp_socket.close()

shutdown_task = await serve_http(
app,
limit_concurrency=async_engine_client.limit_concurrency,
Expand Down

0 comments on commit 47f5e03

Please sign in to comment.