From e62b7236e8e9aef24f9b7854d5d3ba7c74dee50f Mon Sep 17 00:00:00 2001 From: Alois Wohlschlager Date: Sun, 1 Jun 2025 18:59:23 +0200 Subject: [PATCH] libstore/gc: fix auto-GC blocking indefinitely during evaluation The first auto-GC request would not be registered as a waiter due to a logic error. As a result, if that request was synchronous (as happens during evaluation) it would be stuck forever waiting on a promise that will never be fulfilled. Register also the first request properly so that it is notified and unblocked again when the GC has finished. Also add a test verifying that auto-GC triggering during evaluation will not get stuck. Fixes: https://git.lix.systems/lix-project/lix/issues/844 Change-Id: I157afdc737415261e48d6d01d46c586a2927a1ad (cherry picked from commit 4505bfac8e6296068e10a81360ff9e6ec076e16b) --- lix/libstore/gc.cc | 2 +- tests/functional/gc-auto.sh | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lix/libstore/gc.cc b/lix/libstore/gc.cc index 309c30fc6..91ecf0cc3 100644 --- a/lix/libstore/gc.cc +++ b/lix/libstore/gc.cc @@ -966,9 +966,9 @@ try { { auto state(_gcState.lock()); + state->gcWaiters.push_back(std::move(pfp.fulfiller)); if (state->gcRunning) { - state->gcWaiters.push_back(std::move(pfp.fulfiller)); debug("waiting for auto-GC to finish"); goto sync; } diff --git a/tests/functional/gc-auto.sh b/tests/functional/gc-auto.sh index 521d9e539..46ae9c4ee 100644 --- a/tests/functional/gc-auto.sh +++ b/tests/functional/gc-auto.sh @@ -4,6 +4,13 @@ needLocalStore "“min-free” and “max-free” are daemon options" clearStore +fake_free=$TEST_ROOT/fake-free +export _NIX_TEST_FREE_SPACE_FILE=$fake_free +echo 1100 > $fake_free + +# Check that auto-GC during evaluation progresses. +timeout --signal=KILL 10s nix eval --expr 'builtins.toFile "meow" "meow"' --min-free 2000 + garbage1=$(nix store add-path --name garbage1 ./nar-access.sh) garbage2=$(nix store add-path --name garbage2 ./nar-access.sh) garbage3=$(nix store add-path --name garbage3 ./nar-access.sh) @@ -11,10 +18,6 @@ garbage3=$(nix store add-path --name garbage3 ./nar-access.sh) ls -l $garbage3 POSIXLY_CORRECT=1 du $garbage3 -fake_free=$TEST_ROOT/fake-free -export _NIX_TEST_FREE_SPACE_FILE=$fake_free -echo 1100 > $fake_free - fifoLock=$TEST_ROOT/fifoLock mkfifo "$fifoLock"