c2562408988670c1db95ef862f011097bbf54fec galt Mon Feb 21 00:45:33 2022 -0800 Undoing a change made in 2016 since it is not compatible with MacOS. fixes #28948 diff --git src/lib/https.c src/lib/https.c index f734067..ef62c67 100644 --- src/lib/https.c +++ src/lib/https.c @@ -239,59 +239,31 @@ { brd = 0; continue; } else { if (brd == 0) break; ERR_print_errors_fp(stderr); xerr("Error reading SSL connection"); goto cleanup; } } // write the https data received immediately back on socket to user, and it's ok if it blocks. while(bwt < brd) { - // NOTE: Intended as a thread-specific library-safe way not to ignore SIG_PIPE for the entire application. - // temporarily block sigpipe on this thread - sigset_t sigpipe_mask; - sigemptyset(&sigpipe_mask); - sigaddset(&sigpipe_mask, SIGPIPE); - sigset_t saved_mask; - if (pthread_sigmask(SIG_BLOCK, &sigpipe_mask, &saved_mask) == -1) { - perror("pthread_sigmask"); - exit(1); - } int bwtx = write(params->sv[1], bbuf+bwt, brd-bwt); - int saveErrno = errno; - if ((bwtx == -1) && (saveErrno == EPIPE)) - { // if there was a EPIPE, accept and consume the SIGPIPE now. - int sigErr, sig; - if ((sigErr = sigwait(&sigpipe_mask, &sig)) != 0) - { - errno = sigErr; - perror("sigwait"); - exit(1); - } - } - // restore signal mask on this thread - if (pthread_sigmask(SIG_SETMASK, &saved_mask, 0) == -1) - { - perror("pthread_sigmask"); - exit(1); - } - errno = saveErrno; if (bwtx == -1) { if ((errno != 104) // udcCache often closes causing "Connection reset by peer" && (errno != 32)) // udcCache often closes causing "Broken pipe" xerrno("error writing https data back to user pipe"); goto cleanup; } bwt += bwtx; } brd = 0; bwt = 0; } } } @@ -752,33 +724,34 @@ } if (err == 0) { warn("connection timeout to %s", hostName); goto cleanup2; } } struct netConnectHttpsParams *params; AllocVar(params); params->sbio = sbio; socketpair(AF_UNIX, SOCK_STREAM, 0, params->sv); -// netBlockBrokenPipes(); works, but is heavy handed -// and ignores SIGPIPE on all connections for all threads in the entire application. -// We are trying something more subtle and library and thread-friendly instead. +netBlockBrokenPipes(); +// we had a version that was more sophisticated about blocking only the current thread, +// but it only worked for Linux, and fixing it for MacOS would futher increase complexity with little benefit. +// SIGPIPE is often more of a hassle than a help in may cases, so we can just ignore it. int rc; rc = pthread_create(¶ms->thread, NULL, netConnectHttpsThread, (void *)params); if (rc) { errAbort("Unexpected error %d from pthread_create(): %s",rc,strerror(rc)); } return params->sv[0]; /* parent */ cleanup2: if (sbio)