git/t/lib-httpd
Michael Montalbo bf53e31af8 t/lib-httpd: make http-429 first-request check atomic
http-429.sh returns 429 to the first request for an endpoint and
forwards later ones to git-http-backend so the retry succeeds. It
remembers that it has already answered 429 by checking for a shared
state file with "test -f" and creating it with "touch".

That "check-and-set" is not atomic. Apache runs the CGI for several
requests at once, so two of them can pass the "test -f" before either
"touch"es the file, and both then answer as the first request. The
retry flow is mostly sequential, so this has not been observed to fail,
but the race is latent. Replace the check and the "touch" with a single
atomic "mkdir", which fails if the directory already exists, so exactly
one of the concurrent requests is rate-limited and the rest are
forwarded.

The "permanent" mode needs one extra step, for correctness rather than
tidiness. The marker means "429 already served, now forward", so it must
never be visible to a request that must itself return 429. Since
"permanent" returns 429 to every request, it must leave no marker. The
original did not manage this. It ran the "touch" unconditionally and
removed the file with "rm -f" in the "permanent" case, and that
"create-then-remove" has the same racy window: a concurrent "permanent"
request can see the marker before the "rm -f" and be wrongly forwarded.
Skipping the "mkdir" entirely for "permanent" (the "!= permanent" guard)
leaves no marker at all, so every "permanent" request rate-limits.

There is no regression test. The check and the set are adjacent commands
with nothing in between to synchronize on, so the overlap cannot be
forced deterministically, only reproduced by chance; the fix is
preventive.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-08-13 09:39:30 -07:00
..
apache.conf t/lib-httpd: bump apache timeout 2026-06-28 08:32:36 -07:00
apply-one-time-script.sh t/lib-httpd: fix apply-one-time-script race under concurrent requests 2026-08-13 09:39:30 -07:00
broken-smart-http.sh
error-no-report.sh
error-smart-http.sh
error.sh
http-429.sh t/lib-httpd: make http-429 first-request check atomic 2026-08-13 09:39:30 -07:00
incomplete-body-upload-pack-v2-http.sh
incomplete-length-upload-pack-v2-http.sh
nph-custom-auth.sh t5563: refactor for multi-stage authentication 2024-04-16 22:39:08 -07:00
passwd t5550: add netrc tests for http 401/403 2026-01-08 11:02:39 +09:00
proxy-passwd t/lib-httpd: stop using legacy crypt(3) for authentication 2023-11-11 09:00:42 +09:00
ssl.cnf t/lib-httpd: increase ssl key size to 2048 bits 2023-02-01 10:10:34 -08:00