From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Christian Couder <christian.couder@gmail.com>
Cc: Git mailing list <git@vger.kernel.org>,
Harald Nordgren <haraldnordgren@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>
Subject: Re: [PATCH v4 1/2] test-lib: run EXPENSIVE tests one at a time
Date: Tue, 1 Dec 2026 15:44:39 +0530 [thread overview]
Message-ID: <8427f816-2d04-460e-8909-f0740724f2a5@gmail.com> (raw)
In-Reply-To: <CAP8UFD3V8hb+uHzCeEP1Tx8+kPi3rWyrTP7d_4QerJ6XPn+CtQ@mail.gmail.com>
On 11/30/26 19:43, Christian Couder wrote:
>
>> +# 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_=
>> +}
>
> Something like the following would check whose lock it is before releasing it:
>
> ------------
>
> # Remove the lock only if it still names $1 as its owner, so that
> # a lock someone else has just taken is left alone.
> remove_expensive_lock_owned_by_ () {
> test "$(cat "$expensive_lock_" 2>/dev/null)" = "$1" &&
> rm -f "$expensive_lock_"
> }
>
> release_expensive_lock_ () {
> test -n "$have_expensive_lock_" || return 0
> remove_expensive_lock_owned_by_ $$
> have_expensive_lock_=
> }
>
> ------------
>
> This would limit the damage in the case (mentioned in the commit
> message) where two waiters clearing the same stale lock at once let
> two expensive tests run together:
>
> - waiters A and B both see a stale lock,
> - A removes it and takes the lock, then B, which re-checked before A
> removed it, removes A's lock and takes it too,
> - both run, and when A finishes it deletes B's lock, so C starts while
> B is still running.
>
> With the ownership check, A leaves B's lock alone, so the damage stays
> at two tests instead of growing.
>
Interesting. That seems sensible. Will include this.
>> + owner=$(cat "$expensive_lock_" 2>/dev/null)
>> + # A lock carrying our own PID was left by a dead holder whose
>> + # PID we were given again; we know we do not hold it.
>> + if test -n "$owner" &&
>> + { test "$owner" = $$ || ! kill -0 "$owner" 2>/dev/null; }
>> + then
>> + # The holder was killed without releasing the lock.
>> + #
>> + # Another waiter may have taken it over since we
>> + # looked, so only remove it if it is still the same.
>> + if test "$(cat "$expensive_lock_" 2>/dev/null)" = "$owner"
>> + then
>> + rm -f "$expensive_lock_"
>> + fi
>
> Here we could both reuse the remove_expensive_lock_owned_by_() helper
> and be a bit more verbose, for example:
>
Indeed.
> # Another waiter may have taken it over since we
> # looked, so only remove it if it is still the same.
> if remove_expensive_lock_owned_by_ "$owner"
> then
> say >&3 "removing stale EXPENSIVE lock left by PID $owner"
> fi
>
> The extra message might help when reading the logs of a run where a
> script was killed.
>
Makes sense. Will include this too.
>> + continue
>> + fi
>> + if test -z "$waited"
>> + then
>> + say >&3 "waiting for another EXPENSIVE test to finish"
>
> This and the message in expensive_lock_unavailable_() use `say >&3`
> which prints to /dev/null when `-v` or `--verbose-log` is not passed.
>
> This is not an issue for CI runs as `--verbose-log` is used then. But
> someone running tests locally without `-v` might wonder why their
> local run is stuck.
>
Indeed. But I kind of assumed anyone wanting more diagnostics would run
with '-v' anyways.
> With Meson, or when running scripts or `prove` directly, nothing
> cleans test-results/. So a lock left behind by SIGKILL (including the
> OOM killer) can still be there days later. The same PID could then be
> reused by a long-running process of the same user. This would result
> in the script silently waiting forever.
>
> In such a case, printing something even if `-v` or `--verbose-log` is
> not used, would likely make it much easier to understand what's going
> on.
>
> So I would suggest sending this message, as well as the "running
> anyway" and "removing stale" messages, to stderr instead. There are
> only a few dozen EXPENSIVE tests, so this should not add much output.
> The subtests in 2/2 that go through the stale lock removal would then
> need to expect that message on stderr though.
>
> The message would also help even more if it included the holder's PID,
> for example like "waiting for EXPENSIVE lock held by PID 1234".
>
Okay. I guess sending to stderr doesn't do us much harm either. I'll
prefix it with a '#' to ensure it doesn't interfere with TAP.
--
Sivaraam
next prev parent reply other threads:[~2026-12-01 10:14 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 7:40 [PATCH] test-lib: run EXPENSIVE tests one at a time Kaartic Sivaraam
2026-11-19 10:07 ` Patrick Steinhardt
2026-11-19 17:12 ` Kaartic Sivaraam
2026-11-19 17:29 ` [PATCH v2] " Kaartic Sivaraam
2026-11-19 17:33 ` Kaartic Sivaraam
2026-11-20 6:28 ` Junio C Hamano
2026-11-24 13:34 ` Kaartic Sivaraam
2026-11-25 20:21 ` Junio C Hamano
2026-11-27 13:59 ` Kaartic Sivaraam
2026-11-27 18:34 ` Junio C Hamano
2026-11-25 19:09 ` Harald Nordgren
2026-11-27 17:23 ` [PATCH v3] " Kaartic Sivaraam
2026-11-27 20:46 ` Junio C Hamano
2026-11-28 8:06 ` Kaartic Sivaraam
2026-11-28 14:57 ` [PATCH v4 0/2] test-lib: serialize EXPENSIVE tests to avoid OOM in CI Kaartic Sivaraam
2026-11-28 14:57 ` [PATCH v4 1/2] test-lib: run EXPENSIVE tests one at a time Kaartic Sivaraam
2026-11-29 16:55 ` Junio C Hamano
2026-11-30 14:13 ` Christian Couder
2026-12-01 10:14 ` Kaartic Sivaraam [this message]
2026-12-01 11:10 ` Christian Couder
2026-12-01 12:34 ` Kaartic Sivaraam
2026-12-01 7:22 ` Patrick Steinhardt
2026-12-01 8:47 ` Kaartic Sivaraam
2026-12-01 11:07 ` Patrick Steinhardt
2026-12-01 12:50 ` Kaartic Sivaraam
2026-12-01 13:19 ` Patrick Steinhardt
2026-11-28 14:58 ` [PATCH v4 2/2] t0000: test taking over and releasing the EXPENSIVE lock Kaartic Sivaraam
2026-12-01 7:23 ` Patrick Steinhardt
2026-12-01 8:49 ` Kaartic Sivaraam
2026-12-01 19:53 ` [PATCH v5] test-lib: run EXPENSIVE tests one at a time Kaartic Sivaraam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8427f816-2d04-460e-8909-f0740724f2a5@gmail.com \
--to=kaartic.sivaraam@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=haraldnordgren@gmail.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox