Skip to content
Open
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
20 changes: 20 additions & 0 deletions src/python_be.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,26 @@ 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);

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

return nullptr;
}

TRITONBACKEND_ISPEC TRITONSERVER_Error*
TRITONBACKEND_ModelInstanceFinalize(TRITONBACKEND_ModelInstance* instance)
{
Expand Down
32 changes: 28 additions & 4 deletions src/stub_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,29 @@ 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)
if (errno != ECHILD) {
LOG_MESSAGE(
TRITONSERVER_LOG_VERBOSE,
(std::string("waitpid failed for stub process ") +
std::to_string(stub_pid_) + ": " + strerror(errno))
.c_str());
}
return false;
} else if (return_pid == stub_pid_) {
// Process has exited and has been reaped
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this case indicate an error? Is it worthy to be logged?

Copy link
Member Author

Choose a reason for hiding this comment

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

Logging is beneficial, but we may not need to log here since we are already logging the message stub process is not healthy in core. https://github.com/triton-inference-server/core/pull/461/files#diff-2d67039ec4a39ebaa76ab0e875883d5a2ce230cc413d18e09cff4f413a3686ebR479-R481

}

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

Expand Down Expand Up @@ -824,9 +846,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