Skip to content

Commit 4b3337c

Browse files
authored
fix: Prevent deadlock in decoupled BLS and use-after-free in async_exec pybind callback (#439)
1 parent 3033a6b commit 4b3337c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎src/pb_stub.cc‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,8 +1496,16 @@ Stub::GetCUDAMemoryPoolAddress(std::unique_ptr<IPCMessage>& ipc_message)
14961496
*(ipc_message->ResponseMutex())};
14971497
cuda_pool_message_ptr->waiting_on_stub = true;
14981498
ipc_message->ResponseCondition()->notify_all();
1499-
while (cuda_pool_message_ptr->waiting_on_stub) {
1500-
ipc_message->ResponseCondition()->wait(lock);
1499+
// This handler runs on the single ParentToStubMQMonitor thread,
1500+
// which also delivers decoupled BLS responses,
1501+
// so it must not block on the success path.
1502+
// It should only wait when an error message has been written to
1503+
// error_string_shm, so the parent can finish reading it before
1504+
// this function returns and frees that shared memory.
1505+
if (has_exception) {
1506+
while (cuda_pool_message_ptr->waiting_on_stub) {
1507+
ipc_message->ResponseCondition()->wait(lock);
1508+
}
15011509
}
15021510
}
15031511
#endif
@@ -1849,7 +1857,7 @@ PYBIND11_EMBEDDED_MODULE(c_python_backend_utils, module)
18491857
auto stub = Stub::GetOrCreateInstance();
18501858
py::object loop =
18511859
py::module_::import("asyncio").attr("get_running_loop")();
1852-
py::cpp_function callback = [&stub, infer_request, decoupled]() {
1860+
py::cpp_function callback = [stub, infer_request, decoupled]() {
18531861
std::shared_ptr<InferResponse> response =
18541862
infer_request->Exec(decoupled);
18551863
py::object response_object;

0 commit comments

Comments
 (0)