Skip to content

Commit d2abb8b

Browse files
authored
fix: Release GIL during server.stop() to allow request release callbacks to complete (#381)
1 parent 8153c2e commit d2abb8b

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

python/test/test_api.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,6 @@ def test_ready(self):
345345
server = tritonserver.Server(self._server_options).start()
346346
self.assertTrue(server.ready())
347347

348-
@pytest.mark.xfail(
349-
tritonserver.__version__ <= "2.48.0",
350-
reason="Known issue on stop: Exit timeout expired. Exiting immediately",
351-
raises=tritonserver.InternalError,
352-
)
353348
def test_stop(self):
354349
server = tritonserver.Server(self._server_options).start(wait_until_ready=True)
355350

python/tritonserver/_c/tritonserver_pybind.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
// Copyright 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
//
33
// Redistribution and use in source and binary forms, with or without
44
// modification, are permitted provided that the following conditions
@@ -1434,7 +1434,18 @@ class PyServer : public PyWrapper<struct TRITONSERVER_Server> {
14341434
owned_ = true;
14351435
}
14361436

1437-
void Stop() const { ThrowIfError(TRITONSERVER_ServerStop(triton_object_)); }
1437+
void Stop() const
1438+
{
1439+
// ServerStop is blocking for the duration of the server exit timeout, so
1440+
// ensure to release the GIL. This can allow request release callbacks
1441+
// to be interleaved while server is waiting for live requests/models
1442+
// to complete. Without releasing GIL, this function may acquire the GIL
1443+
// first and block the Triton request from being released/freed, thus
1444+
// blocking the server's shutdown in a circular manner thinking a model is
1445+
// still alive.
1446+
py::gil_scoped_release release;
1447+
ThrowIfError(TRITONSERVER_ServerStop(triton_object_));
1448+
}
14381449

14391450
void RegisterModelRepository(
14401451
const std::string& repository_path,

0 commit comments

Comments
 (0)