Skip to content

Commit b7bcacd

Browse files
committed
Update
1 parent cbb42dd commit b7bcacd

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

src/python_be.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,33 @@ TRITONBACKEND_ModelInstanceExecute(
24162416
return nullptr;
24172417
}
24182418

2419+
TRITONBACKEND_ISPEC TRITONSERVER_Error*
2420+
TRITONBACKEND_ModelInstanceReady(TRITONBACKEND_ModelInstance* instance)
2421+
{
2422+
void* vstate;
2423+
RETURN_IF_ERROR(TRITONBACKEND_ModelInstanceState(instance, &vstate));
2424+
ModelInstanceState* instance_state =
2425+
reinterpret_cast<ModelInstanceState*>(vstate);
2426+
2427+
if (!instance_state->Stub()->StubActive()) {
2428+
return TRITONSERVER_ErrorNew(
2429+
TRITONSERVER_ERROR_INTERNAL,
2430+
(std::string("Stub process '") + instance_state->Name() +
2431+
"' is not alive")
2432+
.c_str());
2433+
}
2434+
2435+
if (!instance_state->IsStubProcessAlive()) {
2436+
return TRITONSERVER_ErrorNew(
2437+
TRITONSERVER_ERROR_INTERNAL,
2438+
(std::string("Stub process '") + instance_state->Name() +
2439+
"' is not healthy (unresponsive).")
2440+
.c_str());
2441+
}
2442+
2443+
return nullptr;
2444+
}
2445+
24192446
TRITONBACKEND_ISPEC TRITONSERVER_Error*
24202447
TRITONBACKEND_ModelInstanceFinalize(TRITONBACKEND_ModelInstance* instance)
24212448
{

src/stub_launcher.cc

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,24 @@ StubLauncher::StubActive()
743743
GetExitCodeProcess(stub_pid_.hProcess, &ec);
744744
return (ec == STILL_ACTIVE);
745745
#else
746-
return (stub_pid_ != 0);
746+
if (stub_pid_ == 0) {
747+
return false;
748+
}
749+
750+
int status;
751+
pid_t return_pid = waitpid(stub_pid_, &status, WNOHANG);
752+
if (return_pid == -1) {
753+
// If waitpid fails, it likely means the process no longer exists (ECHILD)
754+
stub_pid_ = 0;
755+
return false;
756+
} else if (return_pid == stub_pid_) {
757+
// Process has exited and has been reaped
758+
stub_pid_ = 0;
759+
return false;
760+
}
761+
762+
// return_pid == 0 means the process is still running
763+
return true;
747764
#endif
748765
}
749766

@@ -824,9 +841,11 @@ StubLauncher::KillStubProcess()
824841
CloseHandle(stub_pid_.hProcess);
825842
CloseHandle(stub_pid_.hThread);
826843
#else
827-
kill(stub_pid_, SIGKILL);
828-
WaitForStubProcess();
829-
stub_pid_ = 0;
844+
if (stub_pid_ != 0) {
845+
kill(stub_pid_, SIGKILL);
846+
WaitForStubProcess();
847+
stub_pid_ = 0;
848+
}
830849
#endif
831850
}
832851

0 commit comments

Comments
 (0)