Skip to content

Commit 8ef250c

Browse files
committed
Merge branch 'jk/epipe-in-async'
Handling of errors while writing into our internal asynchronous process has been made more robust, which reduces flakiness in our tests. * jk/epipe-in-async: t5504: handle expected output from SIGPIPE death test_must_fail: report number of unexpected signal fetch-pack: ignore SIGPIPE in sideband demuxer write_or_die: handle EPIPE in async threads
2 parents 15be621 + 43f3afc commit 8ef250c

File tree

6 files changed

+25
-3
lines changed

6 files changed

+25
-3
lines changed

fetch-pack.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "version.h"
1616
#include "prio-queue.h"
1717
#include "sha1-array.h"
18+
#include "sigchain.h"
1819

1920
static int transfer_unpack_limit = -1;
2021
static int fetch_unpack_limit = -1;
@@ -671,9 +672,12 @@ static int everything_local(struct fetch_pack_args *args,
671672
static int sideband_demux(int in, int out, void *data)
672673
{
673674
int *xd = data;
675+
int ret;
674676

675-
int ret = recv_sideband("fetch-pack", xd[0], out);
677+
sigchain_push(SIGPIPE, SIG_IGN);
678+
ret = recv_sideband("fetch-pack", xd[0], out);
676679
close(out);
680+
sigchain_pop(SIGPIPE);
677681
return ret;
678682
}
679683

run-command.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,11 @@ int in_async(void)
625625
return !pthread_equal(main_thread, pthread_self());
626626
}
627627

628+
void NORETURN async_exit(int code)
629+
{
630+
pthread_exit((void *)(intptr_t)code);
631+
}
632+
628633
#else
629634

630635
static struct {
@@ -670,6 +675,11 @@ int in_async(void)
670675
return process_is_async;
671676
}
672677

678+
void NORETURN async_exit(int code)
679+
{
680+
exit(code);
681+
}
682+
673683
#endif
674684

675685
int start_async(struct async *async)

run-command.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ struct async {
121121
int start_async(struct async *async);
122122
int finish_async(struct async *async);
123123
int in_async(void);
124+
void NORETURN async_exit(int code);
124125

125126
/**
126127
* This callback should initialize the child process and preload the

t/t5504-fetch-receive-strict.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ test_expect_success 'push with receive.fsckobjects' '
101101
git config transfer.fsckobjects false
102102
) &&
103103
test_must_fail ok=sigpipe git push --porcelain dst master:refs/heads/test >act &&
104-
test_cmp exp act
104+
{
105+
test_cmp exp act ||
106+
! test -s act
107+
}
105108
'
106109

107110
test_expect_success 'push with transfer.fsckobjects' '

t/test-lib-functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ test_must_fail () {
617617
return 0
618618
elif test $exit_code -gt 129 && test $exit_code -le 192
619619
then
620-
echo >&2 "test_must_fail: died by signal: $*"
620+
echo >&2 "test_must_fail: died by signal $(($exit_code - 128)): $*"
621621
return 1
622622
elif test $exit_code -eq 127
623623
then

write_or_die.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#include "cache.h"
2+
#include "run-command.h"
23

34
static void check_pipe(int err)
45
{
56
if (err == EPIPE) {
7+
if (in_async())
8+
async_exit(141);
9+
610
signal(SIGPIPE, SIG_DFL);
711
raise(SIGPIPE);
812
/* Should never happen, but just in case... */

0 commit comments

Comments
 (0)