From: "Michael Montalbo via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>, Michael Montalbo <mmontalbo@gmail.com>
Subject: [PATCH v5 0/3] t/lib-httpd: make CGI test helpers concurrency-safe
Date: Tue, 01 Sep 2026 15:53:00 +0000 [thread overview]
Message-ID: <pull.2171.v5.git.1788277983.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2171.git.1783479584.gitgitgadget@gmail.com>
t/lib-httpd.sh provides several helpers that can be invoked concurrently by
Apache while exercising tests. Currently, two of these helpers use state
management logic that fails under certain race conditions.
apply-one-time-script.sh is one of those test helpers. It executes a
"one-time-script" responsible for modifying the response normally returned
by git-http-backend. Sometimes a race between multiple concurrent requests
causes apply-one-time-script.sh to misbehave and return multiple modified
responses or an empty response that results in:
fatal: ... The requested URL returned error: 500 fatal: could not fetch from
promisor remote
This can be seen in the flaky failure of t5616.47 on the macOS CI
runners[1].
Fix this by chaining (&&) the logic for executing "one-time-script" with its
removal, rather than running them as separate actions. Add
t/t5567-one-time-script.sh to verify this fix is effective.
http-429.sh is the other helper whose state management logic can fail under
certain race conditions. However, these failures do not manifest themselves
currently since http-429.sh is invoked sequentially.
As a preventive measure, fix http-429.sh's state management logic so it
relies on an atomic mkdir operation to mark that a 429 was returned rather
than separate "test -f marker", "touch marker", and "rm -f marker" actions
to manage state. http-429.sh is not as straightforward to test as
apply-one-time-script.sh, which is why no regression test was added for the
change.
Finally, document these patterns and anti-patterns in t/lib-httpd.sh for
future developers.
Changes since v4:
* Reword advice about chaining (&&) atomic operations like rm so it refers
to chaining with "the logic guarded by the marker" instead of "the logic
that claims the marker" since the latter is circular and inaccurate
(atomic operations like rm are the logic that claims markers).
[1]
https://github.com/gitgitgadget/git/actions/runs/28756172690/job/85263916762?pr=2169
Michael Montalbo (3):
t/lib-httpd: fix apply-one-time-script race under concurrent requests
t/lib-httpd: make http-429 first-request check atomic
t/lib-httpd: document writing concurrency-safe CGI helpers
t/lib-httpd.sh | 12 ++++
t/lib-httpd/apply-one-time-script.sh | 38 +++++++----
t/lib-httpd/http-429.sh | 22 +++----
t/meson.build | 1 +
t/t5567-one-time-script.sh | 96 ++++++++++++++++++++++++++++
5 files changed, 143 insertions(+), 26 deletions(-)
create mode 100755 t/t5567-one-time-script.sh
base-commit: 5b2471720c93ee30e5764a19f3d3b3ae9ec9712a
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2171%2Fmmontalbo%2Fmm%2Flib-httpd-cgi-safe-proto-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2171/mmontalbo/mm/lib-httpd-cgi-safe-proto-v5
Pull-Request: https://github.com/gitgitgadget/git/pull/2171
Range-diff vs v4:
1: e202142f19 = 1: e202142f19 t/lib-httpd: fix apply-one-time-script race under concurrent requests
2: 79396d491f = 2: 79396d491f t/lib-httpd: make http-429 first-request check atomic
3: d8d11ad246 ! 3: 75a184ca09 t/lib-httpd: document writing concurrency-safe CGI helpers
@@ t/lib-httpd.sh: prepare_httpd() {
+ # - use "mkdir dir" to ensure only one request "succeeds" under some
+ # condition (see http-429.sh).
+ # - chain (&&) atomic operations like "rm marker" (no -f) with the
-+ # logic that "claims" the marker instead of relying on a separate
-+ # "test -f" and "rm marker" check (see apply-one-time-script.sh).
++ # logic that is guarded by the marker instead of relying on a
++ # separate "test -f" and "rm marker" check
++ # (see apply-one-time-script.sh).
+ # - use scratch file names that include the process ID ($$), so
+ # concurrent requests do not overwrite each other's state.
install_script incomplete-length-upload-pack-v2-http.sh
--
gitgitgadget
next prev parent reply other threads:[~2026-09-01 15:53 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 2:59 [PATCH 0/3] t/lib-httpd: make CGI test helpers concurrency-safe Michael Montalbo via GitGitGadget
2026-07-08 2:59 ` [PATCH 1/3] t/lib-httpd: fix apply-one-time-script race under concurrent requests Michael Montalbo via GitGitGadget
2026-07-08 19:54 ` Junio C Hamano
2026-07-09 17:26 ` Michael Montalbo
2026-07-08 2:59 ` [PATCH 2/3] t/lib-httpd: make http-429 first-request check atomic Michael Montalbo via GitGitGadget
2026-07-08 19:58 ` Junio C Hamano
2026-07-08 20:02 ` Junio C Hamano
2026-07-09 18:10 ` Michael Montalbo
2026-07-08 2:59 ` [PATCH 3/3] t/README: document writing concurrency-safe helpers Michael Montalbo via GitGitGadget
2026-07-08 19:59 ` Junio C Hamano
2026-07-10 17:30 ` [PATCH v2 0/3] t/lib-httpd: make CGI test helpers concurrency-safe Michael Montalbo via GitGitGadget
2026-07-10 17:30 ` [PATCH v2 1/3] t/lib-httpd: fix apply-one-time-script race under concurrent requests Michael Montalbo via GitGitGadget
2026-08-04 8:03 ` Patrick Steinhardt
2026-08-07 16:29 ` Michael Montalbo
2026-07-10 17:30 ` [PATCH v2 2/3] t/lib-httpd: make http-429 first-request check atomic Michael Montalbo via GitGitGadget
2026-07-10 17:30 ` [PATCH v2 3/3] t/README: document writing concurrency-safe helpers Michael Montalbo via GitGitGadget
2026-08-04 8:03 ` Patrick Steinhardt
2026-08-07 16:51 ` Michael Montalbo
2026-08-10 6:06 ` Patrick Steinhardt
2026-08-02 3:02 ` [PATCH v2 0/3] t/lib-httpd: make CGI test helpers concurrency-safe Michael Montalbo
2026-08-03 21:55 ` Junio C Hamano
2026-08-13 1:05 ` [PATCH v3 " Michael Montalbo via GitGitGadget
2026-08-13 1:05 ` [PATCH v3 1/3] t/lib-httpd: fix apply-one-time-script race under concurrent requests Michael Montalbo via GitGitGadget
2026-08-13 1:05 ` [PATCH v3 2/3] t/lib-httpd: make http-429 first-request check atomic Michael Montalbo via GitGitGadget
2026-08-31 7:18 ` Patrick Steinhardt
2026-08-31 14:50 ` Junio C Hamano
2026-08-31 17:31 ` Michael Montalbo
2026-08-31 17:09 ` Michael Montalbo
2026-08-13 1:05 ` [PATCH v3 3/3] t/lib-httpd: document writing concurrency-safe CGI helpers Michael Montalbo via GitGitGadget
2026-08-31 7:18 ` Patrick Steinhardt
2026-08-26 19:59 ` [PATCH v3 0/3] t/lib-httpd: make CGI test helpers concurrency-safe Junio C Hamano
2026-08-31 7:18 ` Patrick Steinhardt
2026-09-01 0:27 ` [PATCH v4 " Michael Montalbo via GitGitGadget
2026-09-01 0:27 ` [PATCH v4 1/3] t/lib-httpd: fix apply-one-time-script race under concurrent requests Michael Montalbo via GitGitGadget
2026-09-01 0:27 ` [PATCH v4 2/3] t/lib-httpd: make http-429 first-request check atomic Michael Montalbo via GitGitGadget
2026-09-01 0:27 ` [PATCH v4 3/3] t/lib-httpd: document writing concurrency-safe CGI helpers Michael Montalbo via GitGitGadget
2026-09-01 11:17 ` Patrick Steinhardt
2026-09-01 14:28 ` Michael Montalbo
2026-09-01 15:53 ` Michael Montalbo via GitGitGadget [this message]
2026-09-01 15:53 ` [PATCH v5 1/3] t/lib-httpd: fix apply-one-time-script race under concurrent requests Michael Montalbo via GitGitGadget
2026-09-01 15:53 ` [PATCH v5 2/3] t/lib-httpd: make http-429 first-request check atomic Michael Montalbo via GitGitGadget
2026-09-01 15:53 ` [PATCH v5 3/3] t/lib-httpd: document writing concurrency-safe CGI helpers Michael Montalbo via GitGitGadget
2026-09-03 5:29 ` [PATCH v5 0/3] t/lib-httpd: make CGI test helpers concurrency-safe Patrick Steinhardt
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=pull.2171.v5.git.1788277983.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=mmontalbo@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