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
56 changes: 49 additions & 7 deletions src/stub_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@

#ifdef _WIN32
#include <process.h> // getpid()
#else
#include <sys/wait.h>

#include <csignal>
#endif

extern char** environ;
Expand Down Expand Up @@ -955,6 +959,32 @@ StubLauncher::WaitForStubProcess()
#endif
}

#ifndef _WIN32
namespace {

// True when waitpid status is a crash. SIGKILL is excluded: an unhealthy stub
// is terminated that way on purpose.
bool
StubDiedOnCrashSignal(int status)
{
if (!WIFSIGNALED(status)) {
return false;
}
switch (WTERMSIG(status)) {
case SIGSEGV:
case SIGABRT:
case SIGBUS:
case SIGILL:
case SIGFPE:
return true;
default:
return false;
}
}

} // namespace
#endif

bool
StubLauncher::WaitForStubProcessWithTimeout(int64_t timeout_seconds)
{
Expand All @@ -966,14 +996,23 @@ StubLauncher::WaitForStubProcessWithTimeout(int64_t timeout_seconds)
return true;
}

auto log_crash_signal = [this](int status) {
if (StubDiedOnCrashSignal(status)) {
LOG_MESSAGE(
TRITONSERVER_LOG_ERROR,
(std::string("Python backend stub '") + model_instance_name_ +
"' exited on signal " + std::to_string(WTERMSIG(status)))
.c_str());
}
};

for (int64_t elapsed = 0; elapsed < timeout_seconds; ++elapsed) {
int status;
int status = 0;
pid_t ret = waitpid(stub_pid_, &status, WNOHANG);
if (ret == stub_pid_) {
stub_pid_ = 0;
return true;
}
if (ret == -1) {
if (ret == stub_pid_ || ret == -1) {
if (ret == stub_pid_) {
log_crash_signal(status);
}
stub_pid_ = 0;
return true;
}
Expand All @@ -982,9 +1021,12 @@ StubLauncher::WaitForStubProcessWithTimeout(int64_t timeout_seconds)

// Stub may have exited during the last sleep(1); recheck before killing.
{
int status;
int status = 0;
pid_t ret = waitpid(stub_pid_, &status, WNOHANG);
if (ret == stub_pid_ || ret == -1) {
if (ret == stub_pid_) {
log_crash_signal(status);
}
stub_pid_ = 0;
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/stub_launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class StubLauncher {
void WaitForStubProcess();

// Wait for stub process with timeout. Returns true if the stub exited.
// A stub that exits on SIGSEGV, SIGABRT, SIGBUS, SIGILL, or SIGFPE is logged.
bool WaitForStubProcessWithTimeout(int64_t timeout_seconds);

#ifndef _WIN32
Expand Down
Loading