Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ std::string CaBundlePath() {

#if defined(IGNORE_SIGPIPE)

// Block SIGPIPE signals for the current thread and all threads it creates.
// Block SIGPIPE on the cURL worker thread to prevent writes to closed sockets
// from terminating the process.
int BlockSigpipe() {
sigset_t sigset;
int err;
Expand All @@ -155,13 +156,6 @@ int BlockSigpipe() {
return err;
}

// Curl7.35+OpenSSL can write into closed sockets sometimes which results
// in the process being terminated with SIGPIPE on Linux. Here's
// a workaround for that bug. It block SIGPIPE for the startup thread and
// hence for all other threads in the application. The variable itself is
// not used but can be examined.
int BlockSigpipeResult = BlockSigpipe();

#endif // IGNORE_SIGPIPE

#ifdef OLP_SDK_NETWORK_HAS_PIPE2
Expand Down Expand Up @@ -1231,6 +1225,15 @@ NetworkCurl::RequestHandle* NetworkCurl::Impl::FindRequestHandle(
}

void NetworkCurl::Impl::Run() {
#if defined(IGNORE_SIGPIPE)
const auto block_sigpipe_result = BlockSigpipe();
if (block_sigpipe_result != 0) {
OLP_SDK_LOG_ERROR(kLogTag,
"Failed to block SIGPIPE on cURL worker thread, error="
<< block_sigpipe_result);
}
#endif

olp::utils::Thread::SetCurrentThreadName(kCurlThreadName);

{
Expand Down
Loading