Skip to content

Commit e4c932d

Browse files
committed
Bind api server port before starting engine
1 parent 79c1b83 commit e4c932d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

vllm/entrypoints/openai/api_server.py

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import multiprocessing
55
import os
66
import re
7+
import socket
78
import tempfile
89
from argparse import Namespace
910
from contextlib import asynccontextmanager
@@ -495,13 +496,18 @@ async def run_server(args, **uvicorn_kwargs) -> None:
495496
logger.info("vLLM API server version %s", VLLM_VERSION)
496497
logger.info("args: %s", args)
497498

499+
temp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
500+
temp_socket.bind(("", args.port))
501+
498502
async with build_async_engine_client(args) as async_engine_client:
499503
# If None, creation of the client failed and we exit.
500504
if async_engine_client is None:
501505
return
502506

503507
app = await init_app(async_engine_client, args)
504508

509+
temp_socket.close()
510+
505511
shutdown_task = await serve_http(
506512
app,
507513
engine=async_engine_client,

0 commit comments

Comments
 (0)