From 005517539b886358fefd369b2c47571ff6fe62bb Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Fri, 23 Oct 2020 03:22:22 +0300 Subject: [PATCH] mdbx: adds `SIGPIPE` suppression inside the env_copy-thread. Change-Id: Ib7d22b8db7435b396bd997b65ae1d6d5d3431ba9 --- .github/actions/spelling/expect.txt | 3 +++ src/core.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index ae692c27..28a0b2b4 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -423,6 +423,7 @@ eot EOTDONE EOWNERDEAD EPERM +EPIPE erasevolume EREMOTE EROFS @@ -1429,12 +1430,14 @@ sigemptyset SIGHUP SIGINT SIGKILL +sigmask SIGPIPE sigprocmask SIGSEGV sigset SIGTERM sigusr +sigwait singlemode singleprocess sizeof diff --git a/src/core.c b/src/core.c index 6bca1f9d..19e471f1 100644 --- a/src/core.c +++ b/src/core.c @@ -16198,6 +16198,13 @@ static THREAD_RESULT __cold THREAD_CALL mdbx_env_copythr(void *arg) { uint8_t *ptr; int toggle = 0; +#if defined(EPIPE) && !(defined(_WIN32) || defined(_WIN64)) + sigset_t sigset; + sigemptyset(&sigset); + sigaddset(&sigset, SIGPIPE); + my->mc_error = pthread_sigmask(SIG_BLOCK, &sigset, NULL); +#endif /* EPIPE */ + mdbx_condpair_lock(&my->mc_condpair); while (!my->mc_error) { while (!my->mc_new && !my->mc_error) { @@ -16215,6 +16222,14 @@ static THREAD_RESULT __cold THREAD_CALL mdbx_env_copythr(void *arg) { if (wsize > 0 && !my->mc_error) { int err = mdbx_write(my->mc_fd, ptr, wsize); if (err != MDBX_SUCCESS) { +#if defined(EPIPE) && !(defined(_WIN32) || defined(_WIN64)) + if (err == EPIPE) { + /* Collect the pending SIGPIPE, + * otherwise at least OS X gives it to the process on thread-exit. */ + int unused; + sigwait(&sigset, &unused); + } +#endif /* EPIPE */ my->mc_error = err; goto bailout; }