Merge branch 'jk/epipe-in-async' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 10 Mar 2016 19:13:38 +0000 (11:13 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Mar 2016 19:13:38 +0000 (11:13 -0800)
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

fetch-pack.c
run-command.c
run-command.h
t/t5504-fetch-receive-strict.sh
t/test-lib-functions.sh
write_or_die.c
index 01e34b689b975799610eabc15fc9138990706ff8..f96f6dfb35afb419ac38fcec9b4013fbf0e6d36d 100644 (file)
@@ -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;
@@ -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;
 }
 
index 13fa452e8c3d5a5e20e24a969d53ce7ade4019bf..3add1d66ac344feab2ca39ee6fff663628c5fe32 100644 (file)
@@ -633,6 +633,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 {
@@ -678,6 +683,11 @@ int in_async(void)
        return process_is_async;
 }
 
+void NORETURN async_exit(int code)
+{
+       exit(code);
+}
+
 #endif
 
 int start_async(struct async *async)
index 12bb26c2a6155750203babfec47b08e8bde0ad27..c0969c7695f6b550b382b5704ceb9b2c23b3e3e0 100644 (file)
@@ -121,5 +121,6 @@ struct async {
 int start_async(struct async *async);
 int finish_async(struct async *async);
 int in_async(void);
+void NORETURN async_exit(int code);
 
 #endif
index 89224edcc582e6610fdefd63a8d40048bfe10da0..a3e12d295afedb170b3a917ce9d23122c1a0bc1d 100755 (executable)
@@ -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' '
index c64e5a50258d1b3d3655e2dfcf8f391977c5e758..8d99eb303fd62a1c179ab31f471a3376898586b0 100644 (file)
@@ -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
index e7afe7a295e586d58313e82e87b22de347aef7a1..49e80aa222132c3c151b79bd37749d92a12f745a 100644 (file)
@@ -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... */