Commit 56503c0
committed
t/lib-httpd: add cgi-lib.sh for concurrency-safe CGI helpers
The CGI helpers under t/lib-httpd keep state between requests in the shared
HTTPD_ROOT_PATH, on the assumption that the web server hands them one request
at a time. It does not: the server serves requests concurrently, and a single
Git operation can open more than one request to the same endpoint at once. A
partial fetch that receives a REF_DELTA against a missing promisor object
lazily fetches that base while the first response is still being served, and
protocol v2 and HTTP/2 can multiplex further. A helper that reads shared state
with a "test -f" and then acts on it, or that writes to a fixed-name scratch
file, therefore races with a concurrent request; the loser emits a malformed
response and the server answers HTTP 500.
Rather than fix each helper in isolation, add a small library, cgi-lib.sh,
that captures the safe idioms once: cgi_claim atomically claims a one-shot
marker, and cgi_first_request is an atomic first-wins test-and-set. Scratch
files use a documented $$ suffix rather than a helper, since that is all they
need. Install the library into HTTPD_ROOT_PATH alongside the helpers so they
can source it; the following commits build the stateful helpers on top of it.
Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>1 parent e9019fc commit 56503c0
2 files changed
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
0 commit comments