From: Kaartic Sivaraam Date: Sat, 28 Nov 2026 14:57:58 GMT Subject: [PATCH v4 0/2] test-lib: serialize EXPENSIVE tests to avoid OOM in CI Message-ID: <20261128-ks-ci-long-test-hang-fix-v4-0-f117badd2e13@gmail.com> In-Reply-To: <20261119-ks-ci-long-test-hang-fix-v1-1-45c2fff6d9f0@gmail.com> In recent times, we've been noticing the sanitizer jobs (linux-leaks, linux-reftable-leaks, linux-asan-ubsan) hang and fail with timeout in our GitLab CI runners. On some digging, it turns out that this is because of multiple memory hungry tests running in parallel. So, I thought of suggesting this patch to serialize the expensive tests at least to avoid the putting the CI runners under memory pressure. The GitHub CI runners also observed the same behaviour. Both CI runners are happy with this change. GitHub: https://github.com/sivaraam/git/actions/runs/46125210187/job/140918221115 GitLab: https://gitlab.com/gitlab-org/git/-/pipelines/3126154287 Signed-off-by: Kaartic Sivaraam --- Changes in v4: - Made a few more commit messages tweaks pointed out by Junio. - Moved release_expensive_lock_ above die() to ensure it is always defined before die() is invoked. - All ways of failing to take the lock now print the same message, clean up, and run the test anyway. - 2/2 is new. It adds a few subtests to ensure the lock cleanup happens appropriately. - Link to v3: https://patch.msgid.link/20261127-ks-ci-long-test-hang-fix-v3-1-91b2aac82a1c@gmail.com Changes in v3: - Fixed issues in the commit message as pointed out by Junio. - Fixed a race, pointed out in review, where a waiter could remove a lock another script had just taken, letting two EXPENSIVE tests run at once. A waiter now re-reads the owner and only removes the lock if it still names the same dead process. - Fixed a deadlock where a script killed between creating the lock and recording its PID left a lock that nobody would ever remove. The lock is now a hard link to a file that already holds the PID, so it never exists without an owner. - A lock that names the waiter's own PID (left by a dead holder whose PID was reused) is now treated as stale instead of waited on forever. - If the lock cannot be created although nobody holds it (no hard links, read-only or full disk), the test runs without it instead of waiting forever. - Rewrote the lock part of the commit message for the new scheme. - Link to v2: https://patch.msgid.link/20261119-ks-ci-long-test-hang-fix-v2-1-37011c08380d@gmail.com Changes in v2: - Corrected commit messages as per Patrick's suggestions - Tweaked the shell function comment to avoid mentioning 'prove --jobs' - Made the owner and waiting variables local within acquire_expensive_lock_ - Link to v1: https://patch.msgid.link/20261119-ks-ci-long-test-hang-fix-v1-1-45c2fff6d9f0@gmail.com --- Kaartic Sivaraam (2): test-lib: run EXPENSIVE tests one at a time t0000: test taking over and releasing the EXPENSIVE lock t/README | 8 +++++- t/t0000-basic.sh | 48 ++++++++++++++++++++++++++++++++ t/test-lib.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) Range-diff versus v3: 1: 0d7635ef9f ! 1: 71b765784d test-lib: run EXPENSIVE tests one at a time @@ Commit message Recently, we've acquired quite a few expensive tests in our test suite. For instance, these commits add several tests that require - multi-gigabytes of memory: + multiple gigabytes of memory: - 89048b48fb (t1600-index: add expensive tests for over-long tree paths, 2026-10-16) added tests to t1600 @@ Commit message alongside it. Running the two under a 16GB memory cap reproduces it, with the t1007 git process getting OOM-killed. - GitHub CI runners are no exception and observe the same behaviour. + GitHub CI runners are no exception and experience the same behaviour. Take a lock shared by all test scripts around each EXPENSIVE test, so only one of them runs at a time. Cheap tests in the same scripts keep @@ Commit message and a waiter removes it after re-reading it, so that a lock another waiter has just taken is left alone. Two waiters clearing the same stale lock at once may let two expensive tests run together, which is - rare and better than hanging. If the lock cannot be created although - nobody holds it, e.g. without hard link support, the test runs anyway. + rare and better than hanging. If the lock cannot be taken although + nobody holds it, e.g. without hard link support or on a read-only or + full disk, the test runs anyway. Signed-off-by: Kaartic Sivaraam @@ t/README: appropriately before running "make". Short options can be bundled, i.e --run=:: ## t/test-lib.sh ## -@@ t/test-lib.sh: die () { +@@ t/test-lib.sh: test_missing_prereq= + + test_external_has_tap=0 + ++# This function takes care of cleaning up the lock we ++# acquire in acquire_expensive_lock_. It is defined ++# up here as we refer to it in die(). ++release_expensive_lock_ () { ++ test -n "$have_expensive_lock_" || return 0 ++ rm -f "$expensive_lock_" ++ have_expensive_lock_= ++} ++ + die () { + code=$? + # This is responsible for running the atexit commands even when a # test script run with '--immediate' fails, or when the user hits # ctrl-C, i.e. when 'test_done' is not invoked at all. test_atexit_handler || code=$? @@ t/test-lib.sh: fail_117 () { +expensive_lock_="$TEST_RESULTS_DIR/expensive.lock" +have_expensive_lock_= + ++expensive_lock_unavailable_ () { ++ say >&3 "cannot take the EXPENSIVE lock, running anyway" ++ rm -f "$expensive_lock_.$$" ++} ++ +acquire_expensive_lock_ () { + local owner waited= tmp="$expensive_lock_.$$" misses=0 -+ mkdir -p "$TEST_RESULTS_DIR" || return 1 ++ mkdir -p "$TEST_RESULTS_DIR" || ++ { expensive_lock_unavailable_; return 0; } + # The lock is a hard link to a file that already holds our PID, so + # it never exists without its owner recorded in it. Remove any + # $tmp left by a dead process with our PID first: it may still be + # linked to that process's lock, which writing to it would empty. + rm -f "$tmp" -+ echo $$ >"$tmp" || return 1 ++ echo $$ >"$tmp" || ++ { expensive_lock_unavailable_; return 0; } + while ! ln "$tmp" "$expensive_lock_" 2>/dev/null + do + if ! test -f "$expensive_lock_" @@ t/test-lib.sh: fail_117 () { + # forever. + misses=$((misses + 1)) + test $misses -lt 3 && continue -+ say >&3 "cannot take the EXPENSIVE lock, running anyway" -+ rm -f "$tmp" ++ expensive_lock_unavailable_ + return 0 + fi + misses=0 @@ t/test-lib.sh: fail_117 () { + have_expensive_lock_=t + rm -f "$tmp" +} -+ -+release_expensive_lock_ () { -+ test -n "$have_expensive_lock_" || return 0 -+ rm -f "$expensive_lock_" -+ have_expensive_lock_= -+} + test_run_ () { test_cleanup=: -: ---------- > 2: 6ca7f04310 t0000: test taking over and releasing the EXPENSIVE lock --- base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe change-id: 20261117-ks-ci-long-test-hang-fix-008e72fd40c6