Merge pull request #289 from nix-community/joerg-ci

fix exit status reporting when evaluation fails
This commit is contained in:
Jörg Thalheim 2023-12-16 17:15:45 +01:00 committed by GitHub
commit 4a1123c42d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 13 deletions

View file

@ -113,29 +113,47 @@ void handleBrokenWorkerPipe(Proc &proc, std::string_view msg) {
int rc = waitpid(pid, &status, WNOHANG);
if (rc == 0) {
kill(pid, SIGKILL);
throw Error(
"BUG: while %s, worker pipe got closed but evaluation worker still running?",
msg);
throw Error("BUG: while %s, worker pipe got closed but evaluation "
"worker still running?",
msg);
} else if (rc == -1) {
kill(pid, SIGKILL);
throw Error("BUG: while %s, waitpid for evaluation worker failed: %s",
msg, strerror(errno));
throw Error(
"BUG: while %s, waitpid for evaluation worker failed: %s", msg,
strerror(errno));
} else {
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 1) {
throw Error(
"while %s, evaluation worker exited with exit code 1, "
"(possibly an infinite recursion)",
"(possible infinite recursion)",
msg);
}
throw Error("while %s, evaluation worker exited with %d",
msg, WEXITSTATUS(status));
throw Error("while %s, evaluation worker exited with %d", msg,
WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
if (WTERMSIG(status) == SIGKILL) {
switch (WTERMSIG(status)) {
case SIGKILL:
throw Error(
"while %s, evaluation worker got killed by SIGKILL, maybe "
"while %s, evaluation worker got killed by SIGKILL, "
"maybe "
"memory limit reached?",
msg);
break;
#ifdef __APPLE__
case SIGBUS:
throw Error(
"while %s, evaluation worker got killed by SIGBUS, "
"(possible infinite recursion)",
msg);
break;
#else
case SIGSEGV:
throw Error(
"while %s, evaluation worker got killed by SIGSEGV, "
"(possible infinite recursion)",
msg);
#endif
}
throw Error(
"while %s, evaluation worker got killed by signal %d (%s)",
@ -147,7 +165,7 @@ void handleBrokenWorkerPipe(Proc &proc, std::string_view msg) {
std::string joinAttrPath(json &attrPath) {
std::string joined;
for (auto& element : attrPath) {
for (auto &element : attrPath) {
if (!joined.empty()) {
joined += '.';
}
@ -220,7 +238,8 @@ void collector(Sync<State> &state_, std::condition_variable &wakeup) {
/* Wait for the response. */
auto respString = fromReader->readLine();
if (respString.empty()) {
auto msg = "reading result for attrPath '" + joinAttrPath(attrPath) + "'";
auto msg = "reading result for attrPath '" +
joinAttrPath(attrPath) + "'";
handleBrokenWorkerPipe(*proc.get(), msg);
}
json response;

View file

@ -116,5 +116,5 @@ def test_recursion_error() -> None:
)
assert res.returncode == 1
print(res.stderr)
assert 'packageWithInfiniteRecursion' in res.stderr
assert "packageWithInfiniteRecursion" in res.stderr
assert "possible infinite recursion" in res.stderr