Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/python_be.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,32 @@ TRITONBACKEND_ModelInstanceExecute(
return nullptr;
}

TRITONBACKEND_ISPEC TRITONSERVER_Error*
TRITONBACKEND_ModelInstanceReady(TRITONBACKEND_ModelInstance* instance)
{
void* vstate;
RETURN_IF_ERROR(TRITONBACKEND_ModelInstanceState(instance, &vstate));
ModelInstanceState* instance_state =
reinterpret_cast<ModelInstanceState*>(vstate);

if (!instance_state->Stub()->StubActive()) {
return TRITONSERVER_ErrorNew(
TRITONSERVER_ERROR_INTERNAL, (std::string("Stub process '") +
instance_state->Name() + "' is not alive")
.c_str());
}

if (!instance_state->IsStubProcessAlive()) {
return TRITONSERVER_ErrorNew(
TRITONSERVER_ERROR_INTERNAL,
(std::string("Stub process '") + instance_state->Name() +
"' is not healthy (unresponsive).")
.c_str());
}
Comment on lines +2427 to +2440
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two checks appear redundant—both StubActive() and IsStubProcessAlive() seem to verify process health. If they check different conditions, consider consolidating them into a single health check method or adding comments to clarify their distinct purposes.

Copilot uses AI. Check for mistakes.

return nullptr;
}

TRITONBACKEND_ISPEC TRITONSERVER_Error*
TRITONBACKEND_ModelInstanceFinalize(TRITONBACKEND_ModelInstance* instance)
{
Expand Down
27 changes: 23 additions & 4 deletions src/stub_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,24 @@ StubLauncher::StubActive()
GetExitCodeProcess(stub_pid_.hProcess, &ec);
return (ec == STILL_ACTIVE);
#else
return (stub_pid_ != 0);
if (stub_pid_ == 0) {
return false;
}

int status;
pid_t return_pid = waitpid(stub_pid_, &status, WNOHANG);
if (return_pid == -1) {
// If waitpid fails, it likely means the process no longer exists (ECHILD)
stub_pid_ = 0;
return false;
Comment on lines +752 to +755
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When waitpid fails, consider logging the specific errno value (e.g., ECHILD, EINVAL) to aid debugging. The current comment mentions ECHILD but doesn't verify it, which could mask other failure modes.

Copilot uses AI. Check for mistakes.
} else if (return_pid == stub_pid_) {
// Process has exited and has been reaped
stub_pid_ = 0;
return false;
}

// return_pid == 0 means the process is still running
return true;
#endif
}

Expand Down Expand Up @@ -824,9 +841,11 @@ StubLauncher::KillStubProcess()
CloseHandle(stub_pid_.hProcess);
CloseHandle(stub_pid_.hThread);
#else
kill(stub_pid_, SIGKILL);
WaitForStubProcess();
stub_pid_ = 0;
if (stub_pid_ != 0) {
kill(stub_pid_, SIGKILL);
WaitForStubProcess();
stub_pid_ = 0;
}
#endif
}

Expand Down
Loading