Skip to content

Commit a7b3cf5

Browse files
authored
Revert "add shutdown endpoint w/ test (#507)" (#509)
This reverts commit 7fcbdfb.
1 parent 7fcbdfb commit a7b3cf5

File tree

2 files changed

+1
-45
lines changed

2 files changed

+1
-45
lines changed

src/litserve/server.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ def __init__(
130130
api_path: str = "/predict",
131131
healthcheck_path: str = "/health",
132132
info_path: str = "/info",
133-
shutdown_path: str = "/shutdown",
134133
model_metadata: Optional[dict] = None,
135134
stream: bool = False,
136135
spec: Optional[LitSpec] = None,
@@ -155,7 +154,6 @@ def __init__(
155154
api_path: URL path for the prediction endpoint.
156155
healthcheck_path: URL path for the health check endpoint.
157156
info_path: URL path for the server and model information endpoint.
158-
shutdown_path: URL path for the server shutdown endpoint.
159157
model_metadata: Metadata about the model, shown at the info endpoint.
160158
stream: Whether to enable streaming responses.
161159
spec: Specification for the API, such as OpenAISpec or custom specs.
@@ -222,9 +220,6 @@ def __init__(
222220
"info_path must start with '/'. Please provide a valid api path like '/info', '/details', or '/v1/info'"
223221
)
224222

225-
if not shutdown_path.startswith("/"):
226-
raise ValueError("shutdown_path must start with '/'. Please provide a valid api path like '/shutdown'")
227-
228223
try:
229224
json.dumps(model_metadata)
230225
except (TypeError, ValueError):
@@ -248,7 +243,6 @@ def __init__(
248243
self.api_path = api_path
249244
self.healthcheck_path = healthcheck_path
250245
self.info_path = info_path
251-
self.shutdown_path = shutdown_path
252246
self.track_requests = track_requests
253247
self.timeout = timeout
254248
lit_api.stream = stream
@@ -453,16 +447,6 @@ async def info(request: Request) -> Response:
453447
}
454448
)
455449

456-
@self.app.post(self.shutdown_path, dependencies=[Depends(self.setup_auth())])
457-
async def shutdown(request: Request):
458-
server = self.app.state.server
459-
print("Initiating shutdown...")
460-
if server.should_exit:
461-
return Response(content="Shutdown already in progress", status_code=400)
462-
server.should_exit = True
463-
464-
return Response(content="Server has been shutdown")
465-
466450
async def predict(request: self.request_type) -> self.response_type:
467451
self._callback_runner.trigger_event(
468452
EventTypes.ON_REQUEST.value,
@@ -633,14 +617,12 @@ def run(
633617
print(f"Uvicorn worker {i} : [{uw.pid}]")
634618
uw.join()
635619
finally:
620+
print("Shutting down LitServe")
636621
self._transport.close()
637-
print("Transport closed")
638622
for iw in inference_workers:
639623
iw: Process
640-
print(f"Terminating worker [PID {iw.pid}]")
641624
iw.terminate()
642625
iw.join()
643-
print("Shutting down LitServe")
644626
manager.shutdown()
645627

646628
def _prepare_app_run(self, app: FastAPI):
@@ -669,7 +651,6 @@ def _start_server(self, port, num_uvicorn_servers, log_level, sockets, uvicorn_w
669651
# https://github.com/encode/uvicorn/pull/802
670652
config.workers = num_uvicorn_servers
671653
server = uvicorn.Server(config=config)
672-
self.app.state.server = server
673654
if uvicorn_worker_type == "process":
674655
ctx = mp.get_context("fork")
675656
w = ctx.Process(target=server.run, args=(sockets,))

tests/test_simple.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import time
1616
from concurrent.futures import ThreadPoolExecutor
1717
from contextlib import ExitStack
18-
from types import SimpleNamespace
1918

2019
import numpy as np
2120
import pytest
@@ -148,30 +147,6 @@ def test_workers_health_with_custom_health_method(use_zmq):
148147
assert response.text == "ok"
149148

150149

151-
def test_shutdown_endpoint():
152-
server = LitServer(
153-
SlowSetupLitAPI(),
154-
accelerator="cpu",
155-
shutdown_path="/shutdown",
156-
devices=1,
157-
workers_per_device=1,
158-
)
159-
160-
server.app.state.server = SimpleNamespace(should_exit=False)
161-
162-
with wrap_litserve_start(server) as server, TestClient(server.app) as client:
163-
response = client.post("/shutdown")
164-
assert response.status_code == 200
165-
assert "shutdown" in response.text.lower()
166-
time.sleep(0.5)
167-
assert server.app.state.server.should_exit is True, "Server should be marked for shutdown"
168-
169-
time.sleep(1)
170-
response = client.post("/shutdown")
171-
assert response.status_code == 400
172-
assert "shutdown already" in response.text.lower()
173-
174-
175150
def make_load_request(server, outputs):
176151
with TestClient(server.app) as client:
177152
for i in range(100):

0 commit comments

Comments
 (0)