Skip to content

Commit 75b7cb5

Browse files
peffgitster
authored andcommitted
t1800: test SIGPIPE with parallel hooks
We recently fixed a bug in commit 2226ffa (run_processes_parallel(): fix order of sigpipe handling, 2026-04-08) where a hook that caused us to get SIGPIPE would accidentally trigger the run_processes_parallel() cleanup handler killing the child processes. For a single hook, this meant killing the already-exited hook. This case was triggered by our tests, but was only a problem on some platforms. But if you have multiple hooks running in parallel, this causes a problem everywhere, since one hook failing to read its input would take down all hooks. Now that we have parallel hook support, we can add a test for this case. It should pass already, due to the existing fix. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 495b7d5 commit 75b7cb5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

t/t1800-hook.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,4 +1190,42 @@ test_expect_success 'friendly-name matching unknown event warns' '
11901190
test_grep "same as its event" err
11911191
'
11921192

1193+
test_expect_success 'hooks in parallel that do not read input' '
1194+
# Add this to our $PATH to avoid having to write the whole trash
1195+
# directory into our config options, which would require quoting.
1196+
mkdir bin &&
1197+
PATH=$PWD/bin:$PATH &&
1198+
1199+
write_script bin/hook-fast <<-\EOF &&
1200+
# This hook does not read its input, so the parent process
1201+
# may see SIGPIPE if it is not ignored. It should happen
1202+
# relatively quickly.
1203+
exit 0
1204+
EOF
1205+
1206+
write_script bin/hook-slow <<-\EOF &&
1207+
# This hook is slow, so we expect it to still be running
1208+
# when the other hook has exited (and the parent has a pipe error
1209+
# writing to it).
1210+
#
1211+
# So we want to be slow enough that we expect this to happen, but not
1212+
# so slow that the test takes forever. 1 second is probably enough
1213+
# in practice (and if it is occasionally not on a loaded system, we
1214+
# will err on the side of having the test pass).
1215+
sleep 1
1216+
exit 0
1217+
EOF
1218+
1219+
git init --bare parallel.git &&
1220+
git -C parallel.git config hook.fast.command "hook-fast" &&
1221+
git -C parallel.git config hook.fast.event pre-receive &&
1222+
git -C parallel.git config hook.fast.parallel true &&
1223+
git -C parallel.git config hook.slow.command "hook-slow" &&
1224+
git -C parallel.git config hook.slow.event pre-receive &&
1225+
git -C parallel.git config hook.slow.parallel true &&
1226+
git -C parallel.git config hook.jobs 2 &&
1227+
1228+
git push ./parallel.git "+refs/heads/*:refs/heads/*"
1229+
'
1230+
11931231
test_done

0 commit comments

Comments
 (0)