From 27b4fe81640aa8f94f63bfc8fcb9820f34687114 Mon Sep 17 00:00:00 2001 From: keertk Date: Wed, 17 May 2023 22:26:50 +0000 Subject: [PATCH] blaze_util_posix: handle killpg failures (#18403) In case Bazel JVM server is stuck, it would be useful to know whether the SIGKILL was sent successfully or not. If not, log out the error message from errno. Closes #18299. PiperOrigin-RevId: 530615358 Change-Id: I4ddf9996ce80520ff19c306fe95429550e931a8b Co-authored-by: Son Luong Ngoc --- src/main/cpp/blaze_util_posix.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc index a3ab69e17e0985..e046663c5f94c0 100644 --- a/src/main/cpp/blaze_util_posix.cc +++ b/src/main/cpp/blaze_util_posix.cc @@ -724,7 +724,12 @@ void ReleaseLock(BlazeLock* blaze_lock) { bool KillServerProcess(int pid, const blaze_util::Path& output_base) { // Kill the process and make sure it's dead before proceeding. - killpg(pid, SIGKILL); + errno = 0; + if (killpg(pid, SIGKILL) == -1) { + BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR) + << "Attempted to kill stale server process (pid=" << pid + << ") using SIGKILL: " << GetLastErrorString(); + } if (!AwaitServerProcessTermination(pid, output_base, kPostKillGracePeriodSeconds)) { BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)