Skip to content

Commit 5d06638

Browse files
authored
Merge pull request #14260 from roberth/ulimit
Clarify setStackSize error message and warn if not possible
2 parents c7b61f3 + 261f674 commit 5d06638

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/libutil/current-process.cc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "nix/util/file-system.hh"
88
#include "nix/util/processes.hh"
99
#include "nix/util/signals.hh"
10+
#include "nix/util/environment-variables.hh"
1011
#include <math.h>
1112

1213
#ifdef __APPLE__
@@ -65,13 +66,27 @@ void setStackSize(size_t stackSize)
6566
struct rlimit limit;
6667
if (getrlimit(RLIMIT_STACK, &limit) == 0 && static_cast<size_t>(limit.rlim_cur) < stackSize) {
6768
savedStackSize = limit.rlim_cur;
68-
limit.rlim_cur = std::min(static_cast<rlim_t>(stackSize), limit.rlim_max);
69+
if (limit.rlim_max < static_cast<rlim_t>(stackSize)) {
70+
if (getEnv("_NIX_TEST_NO_ENVIRONMENT_WARNINGS") != "1") {
71+
logger->log(
72+
lvlWarn,
73+
HintFmt(
74+
"Stack size hard limit is %1%, which is less than the desired %2%. If possible, increase the hard limit, e.g. with 'ulimit -Hs %3%'.",
75+
limit.rlim_max,
76+
stackSize,
77+
stackSize / 1024)
78+
.str());
79+
}
80+
}
81+
auto requestedSize = std::min(static_cast<rlim_t>(stackSize), limit.rlim_max);
82+
limit.rlim_cur = requestedSize;
6983
if (setrlimit(RLIMIT_STACK, &limit) != 0) {
7084
logger->log(
7185
lvlError,
7286
HintFmt(
73-
"Failed to increase stack size from %1% to %2% (maximum allowed stack size: %3%): %4%",
87+
"Failed to increase stack size from %1% to %2% (desired: %3%, maximum allowed: %4%): %5%",
7488
savedStackSize,
89+
requestedSize,
7590
stackSize,
7691
limit.rlim_max,
7792
std::strerror(errno))

src/nix/main.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,9 @@ int main(int argc, char ** argv)
584584
#ifndef _WIN32
585585
// Increase the default stack size for the evaluator and for
586586
// libstdc++'s std::regex.
587-
nix::setStackSize(64 * 1024 * 1024);
587+
// This used to be 64 MiB, but macOS as deployed on GitHub Actions has a
588+
// hard limit slightly under that, so we round it down a bit.
589+
nix::setStackSize(60 * 1024 * 1024);
588590
#endif
589591

590592
return nix::handleExceptions(argv[0], [&]() { nix::mainWrapped(argc, argv); });

tests/functional/common/vars.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ if ! isTestOnNixOS; then
4949
fi
5050
export _NIX_IN_TEST=$TEST_ROOT/shared
5151
export _NIX_TEST_NO_LSOF=1
52+
# Suppress warnings that depend on the test environment (e.g., ulimit warnings)
53+
# to avoid non-deterministic test failures in golden tests
54+
export _NIX_TEST_NO_ENVIRONMENT_WARNINGS=1
5255
export NIX_REMOTE=${NIX_REMOTE_-}
5356

5457
fi # ! isTestOnNixOS

0 commit comments

Comments
 (0)