Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/libstore/gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ void LocalStore::addTempRoot(const StorePath & path)
try {
nix::connect(fdRootsSocket->get(), socketPath);
} catch (SysError & e) {
/* The garbage collector may have exited, so we need to
restart. */
if (e.errNo == ECONNREFUSED) {
/* The garbage collector may have exited or not
created the socket yet, so we need to restart. */
if (e.errNo == ECONNREFUSED || e.errNo == ENOENT) {
debug("GC socket connection refused");
fdRootsSocket->close();
goto restart;
Expand Down Expand Up @@ -507,6 +507,11 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
auto fdGCLock = openGCLock();
FdLock gcLock(fdGCLock.get(), ltWrite, true, "waiting for the big garbage collector lock...");

/* Synchronisation point to test ENOENT handling in
addTempRoot(), see tests/gc-non-blocking.sh. */
if (auto p = getEnv("_NIX_TEST_GC_SYNC_2"))
readFile(*p);

/* Start the server for receiving new roots. */
auto socketPath = stateDir.get() + gcSocketPath;
createDirs(dirOf(socketPath));
Expand Down Expand Up @@ -776,7 +781,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
}
};

/* Synchronisation point for testing, see tests/functional/gc-concurrent.sh. */
/* Synchronisation point for testing, see tests/gc-non-blocking.sh. */
if (auto p = getEnv("_NIX_TEST_GC_SYNC"))
readFile(*p);

Expand Down
7 changes: 6 additions & 1 deletion tests/functional/gc-non-blocking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ clearStore
fifo=$TEST_ROOT/test.fifo
mkfifo "$fifo"

fifo2=$TEST_ROOT/test2.fifo
mkfifo "$fifo2"

dummy=$(nix store add-path ./simple.nix)

running=$TEST_ROOT/running
touch $running

(_NIX_TEST_GC_SYNC=$fifo nix-store --gc -vvvvv; rm $running) &
(_NIX_TEST_GC_SYNC=$fifo _NIX_TEST_GC_SYNC_2=$fifo2 nix-store --gc -vvvvv; rm $running) &
pid=$!

sleep 2

(sleep 1; echo > $fifo2) &

outPath=$(nix-build --max-silent-time 60 -o "$TEST_ROOT/result" -E "
with import ./config.nix;
mkDerivation {
Expand Down
Loading