git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 0/2] test-lib: serialize EXPENSIVE tests to avoid OOM in CI

From
Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Date
Nov 28, 2026, 14:57 UTC
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 <kaartic.sivaraam@gmail.com>
---
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 <kaartic.sivaraam@gmail.com>
     
    @@ t/README: appropriately before running "make". Short options can be bundled, i.e
      --run=<test-selector>::
     
      ## 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

Previous: Kaartic SivaraamNext: Kaartic Sivaraam
Message 15 of 32 in “test-lib: run EXPENSIVE tests one at a time”
  1. test-lib: run EXPENSIVE tests one at a timeKaartic Sivaraam, Nov 19, 2026
  2. Patrick SteinhardtNov 19, 2026
  3. Kaartic SivaraamNov 19, 2026
  4. test-lib: run EXPENSIVE tests one at a timeKaartic Sivaraam, Nov 19, 2026
  5. Kaartic SivaraamNov 19, 2026
  6. Junio C HamanoNov 20, 2026
  7. Kaartic SivaraamNov 24, 2026
  8. Junio C HamanoNov 25, 2026
  9. Kaartic SivaraamNov 27, 2026
  10. Junio C HamanoNov 27, 2026
  11. Harald NordgrenNov 25, 2026
  12. test-lib: run EXPENSIVE tests one at a timeKaartic Sivaraam, Nov 27, 2026
  13. Junio C HamanoNov 27, 2026
  14. Kaartic SivaraamNov 28, 2026
  15. 0/2 test-lib: serialize EXPENSIVE tests to avoid OOM in CIKaartic Sivaraam, Nov 28, 2026
  16. 1/2 test-lib: run EXPENSIVE tests one at a timeKaartic Sivaraam, Nov 28, 2026
  17. Junio C HamanoNov 29, 2026
  18. Christian CouderNov 30, 2026
  19. Kaartic SivaraamDec 1, 2026
  20. Christian CouderDec 1, 2026
  21. Kaartic SivaraamDec 1, 2026
  22. Patrick SteinhardtDec 1, 2026
  23. Kaartic SivaraamDec 1, 2026
  24. Patrick SteinhardtDec 1, 2026
  25. Kaartic SivaraamDec 1, 2026
  26. Patrick SteinhardtDec 1, 2026
  27. 2/2 t0000: test taking over and releasing the EXPENSIVE lockKaartic Sivaraam, Nov 28, 2026
  28. Patrick SteinhardtDec 1, 2026
  29. Kaartic SivaraamDec 1, 2026
  30. test-lib: run EXPENSIVE tests one at a timeKaartic Sivaraam, Dec 1, 2026
  31. Patrick SteinhardtDec 3, 2026
  32. Kaartic SivaraamDec 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.