Skip to content

Commit 3823f7a

Browse files
committed
LocalStore::addTempRoot(): Handle ENOENT
If the garbage collector has acquired the global GC lock, but hasn't created the GC socket yet, then a client attempting to connect would get ENOENT. Note that this only happens when the GC runs for the first time on a machine. Subsequently clients will get ECONNREFUSED which was already handled. Fixes #7370.
1 parent f5e620b commit 3823f7a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/libstore/gc.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ void LocalStore::addTempRoot(const StorePath & path)
138138
try {
139139
nix::connect(fdRootsSocket->get(), socketPath);
140140
} catch (SysError & e) {
141-
/* The garbage collector may have exited, so we need to
142-
restart. */
143-
if (e.errNo == ECONNREFUSED) {
141+
/* The garbage collector may have exited or not
142+
created the socket yet, so we need to restart. */
143+
if (e.errNo == ECONNREFUSED || e.errNo == ENOENT) {
144144
debug("GC socket connection refused");
145145
fdRootsSocket->close();
146146
goto restart;
@@ -503,6 +503,11 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
503503
auto fdGCLock = openGCLock();
504504
FdLock gcLock(fdGCLock.get(), ltWrite, true, "waiting for the big garbage collector lock...");
505505

506+
/* Synchronisation point to test ENOENT handling in
507+
LocalStore::addTempRoot(), see tests/gc-non-blocking.sh. */
508+
if (auto p = getEnv("_NIX_TEST_GC_SYNC_2"))
509+
readFile(*p);
510+
506511
/* Start the server for receiving new roots. */
507512
auto socketPath = stateDir.get() + gcSocketPath;
508513
createDirs(dirOf(socketPath));
@@ -772,7 +777,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
772777
}
773778
};
774779

775-
/* Synchronisation point for testing, see tests/gc-concurrent.sh. */
780+
/* Synchronisation point for testing, see tests/gc-non-blocking.sh. */
776781
if (auto p = getEnv("_NIX_TEST_GC_SYNC"))
777782
readFile(*p);
778783

tests/gc-non-blocking.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ clearStore
99
fifo=$TEST_ROOT/test.fifo
1010
mkfifo "$fifo"
1111

12+
fifo2=$TEST_ROOT/test2.fifo
13+
mkfifo "$fifo2"
14+
1215
dummy=$(nix store add-path ./simple.nix)
1316

1417
running=$TEST_ROOT/running
1518
touch $running
1619

17-
(_NIX_TEST_GC_SYNC=$fifo nix-store --gc -vvvvv; rm $running) &
20+
(_NIX_TEST_GC_SYNC=$fifo _NIX_TEST_GC_SYNC_2=$fifo2 nix-store --gc -vvvvv; rm $running) &
1821
pid=$!
1922

2023
sleep 2
2124

25+
(sleep 1; echo > $fifo2) &
26+
2227
outPath=$(nix-build --max-silent-time 60 -o "$TEST_ROOT/result" -E "
2328
with import ./config.nix;
2429
mkDerivation {

0 commit comments

Comments
 (0)