From 9e6705c44b9910384c9b6eaf100b48f17f27f88a Mon Sep 17 00:00:00 2001 From: Alexey Nadtochiy Date: Thu, 16 Apr 2026 13:13:06 +0300 Subject: [PATCH] fix: https://github.com/triton-inference-server/server/issues/8537 --- src/pb_stub.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pb_stub.cc b/src/pb_stub.cc index 173a9c3e..ed3046f4 100644 --- a/src/pb_stub.cc +++ b/src/pb_stub.cc @@ -936,10 +936,13 @@ Stub::RunCoroutine(py::object coroutine, bool in_background) py::object py_future = py::module_::import("asyncio").attr( "run_coroutine_threadsafe")(coroutine, loop); if (in_background) { + // We should add the future to background_futures_ before attaching a + // done callback to avoid the issue described here: + // https://github.com/triton-inference-server/server/issues/8537 + background_futures_.attr("add")(py_future); py_future.attr("add_done_callback")( py::module_::import("c_python_backend_utils") .attr("async_event_future_done_callback")); - background_futures_.attr("add")(py_future); return py::none(); } return py_future.attr("result")();