From 093b8ce5cccd7aac3996bea5a293f0e0172fad95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 16 Dec 2023 11:44:02 +0100 Subject: [PATCH 1/2] apply treefmt --- src/nix-eval-jobs.cc | 28 +++++++++++++++------------- tests/test_eval.py | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index 44b88e7..3c7280d 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -113,13 +113,14 @@ 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) { @@ -128,14 +129,14 @@ void handleBrokenWorkerPipe(Proc &proc, std::string_view msg) { "(possibly an 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) { - throw Error( - "while %s, evaluation worker got killed by SIGKILL, maybe " - "memory limit reached?", - msg); + throw Error("while %s, evaluation worker got killed by " + "SIGKILL, maybe " + "memory limit reached?", + msg); } throw Error( "while %s, evaluation worker got killed by signal %d (%s)", @@ -147,7 +148,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 +221,8 @@ void collector(Sync &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; diff --git a/tests/test_eval.py b/tests/test_eval.py index 93a17ac..8fa41cb 100644 --- a/tests/test_eval.py +++ b/tests/test_eval.py @@ -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 From b73f7ceff479a96fad9d79ffdbfda346ec0bd567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 16 Dec 2023 11:53:10 +0100 Subject: [PATCH 2/2] classify SIGSEV/SIGBUS as infinite recursion errors --- src/nix-eval-jobs.cc | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index 3c7280d..187c95d 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -126,17 +126,34 @@ void handleBrokenWorkerPipe(Proc &proc, std::string_view msg) { 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)); } else if (WIFSIGNALED(status)) { - if (WTERMSIG(status) == SIGKILL) { - throw Error("while %s, evaluation worker got killed by " - "SIGKILL, maybe " - "memory limit reached?", - msg); + switch (WTERMSIG(status)) { + case SIGKILL: + throw Error( + "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)",