From 521380076d5f10dc7dfbdf89690e46ac0da0acf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 10 Dec 2023 21:20:45 +0100 Subject: [PATCH] release proc.pid properly before calling waitpid() --- src/nix-eval-jobs.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index fce0aa6..0fe5a39 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -85,23 +86,23 @@ struct State { }; void handleBrokenWorkerPipe(Proc &proc) { + // we already took the process status from Proc, no + // need to wait for it again to avoid error messages + pid_t pid = proc.pid.release(); while (1) { - int rc = waitpid(proc.pid, nullptr, WNOHANG); + int rc = waitpid(pid, nullptr, WNOHANG); if (rc == 0) { - proc.pid = -1; // we already took the process status from Proc, no - // need to wait for it again to avoid error messages + kill(pid, SIGKILL); throw Error("BUG: worker pipe closed but worker still running?"); } else if (rc == -1) { - proc.pid = -1; + kill(pid, SIGKILL); throw Error("BUG: waitpid waiting for worker failed: %s", strerror(errno)); } else { if (WIFEXITED(rc)) { - proc.pid = -1; throw Error("evaluation worker exited with %d", WEXITSTATUS(rc)); } else if (WIFSIGNALED(rc)) { - proc.pid = -1; if (WTERMSIG(rc) == SIGKILL) { throw Error("evaluation worker killed by SIGKILL, maybe " "memory limit reached?");