Skip to content

Commit

Permalink
Merge branch 'jk/epipe-in-async'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Junio C Hamano committed Feb 26, 2016
2 parents 15be621 + 43f3afc commit 8ef250c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
6 changes: 5 additions & 1 deletion fetch-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "version.h"
#include "prio-queue.h"
#include "sha1-array.h"
#include "sigchain.h"

static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
Expand Down Expand Up @@ -671,9 +672,12 @@ static int everything_local(struct fetch_pack_args *args,
static int sideband_demux(int in, int out, void *data)
{
int *xd = data;
int ret;

int ret = recv_sideband("fetch-pack", xd[0], out);
sigchain_push(SIGPIPE, SIG_IGN);
ret = recv_sideband("fetch-pack", xd[0], out);
close(out);
sigchain_pop(SIGPIPE);
return ret;
}

Expand Down
10 changes: 10 additions & 0 deletions run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,11 @@ int in_async(void)
return !pthread_equal(main_thread, pthread_self());
}

void NORETURN async_exit(int code)
{
pthread_exit((void *)(intptr_t)code);
}

#else

static struct {
Expand Down Expand Up @@ -670,6 +675,11 @@ int in_async(void)
return process_is_async;
}

void NORETURN async_exit(int code)
{
exit(code);
}

#endif

int start_async(struct async *async)
Expand Down
1 change: 1 addition & 0 deletions run-command.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct async {
int start_async(struct async *async);
int finish_async(struct async *async);
int in_async(void);
void NORETURN async_exit(int code);

/**
* This callback should initialize the child process and preload the
Expand Down
5 changes: 4 additions & 1 deletion t/t5504-fetch-receive-strict.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ test_expect_success 'push with receive.fsckobjects' '
git config transfer.fsckobjects false
) &&
test_must_fail ok=sigpipe git push --porcelain dst master:refs/heads/test >act &&
test_cmp exp act
{
test_cmp exp act ||
! test -s act
}
'

test_expect_success 'push with transfer.fsckobjects' '
Expand Down
2 changes: 1 addition & 1 deletion t/test-lib-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ test_must_fail () {
return 0
elif test $exit_code -gt 129 && test $exit_code -le 192
then
echo >&2 "test_must_fail: died by signal: $*"
echo >&2 "test_must_fail: died by signal $(($exit_code - 128)): $*"
return 1
elif test $exit_code -eq 127
then
Expand Down
4 changes: 4 additions & 0 deletions write_or_die.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include "cache.h"
#include "run-command.h"

static void check_pipe(int err)
{
if (err == EPIPE) {
if (in_async())
async_exit(141);

signal(SIGPIPE, SIG_DFL);
raise(SIGPIPE);
/* Should never happen, but just in case... */
Expand Down

0 comments on commit 8ef250c

Please sign in to comment.