Skip to content

Commit 5e07390

Browse files
committed
[Bugfix] fix server startup for embedding models/in-process frontend
vllm-project#8491 (comment)
1 parent 0f6d7a9 commit 5e07390

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

vllm/entrypoints/openai/api_server.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,11 @@ async def run_server(args, **uvicorn_kwargs) -> None:
536536
raise KeyError(f"invalid tool call parser: {args.tool_call_parser} "
537537
f"(chose from {{ {','.join(valide_tool_parses)} }})")
538538

539-
temp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
540-
temp_socket.bind(("", args.port))
539+
# workaround to make sure that we bind the port before the engine is set up.
540+
# This avoids race conditions with ray.
541+
# see https://github.com/vllm-project/vllm/issues/8204
542+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
543+
sock.bind(("", args.port))
541544

542545
def signal_handler(*_) -> None:
543546
# Interrupt server on sigterm while initializing
@@ -551,8 +554,6 @@ def signal_handler(*_) -> None:
551554
model_config = await engine_client.get_model_config()
552555
init_app_state(engine_client, model_config, app.state, args)
553556

554-
temp_socket.close()
555-
556557
shutdown_task = await serve_http(
557558
app,
558559
host=args.host,
@@ -563,6 +564,7 @@ def signal_handler(*_) -> None:
563564
ssl_certfile=args.ssl_certfile,
564565
ssl_ca_certs=args.ssl_ca_certs,
565566
ssl_cert_reqs=args.ssl_cert_reqs,
567+
fd=sock.fileno(),
566568
**uvicorn_kwargs,
567569
)
568570

0 commit comments

Comments
 (0)