From f46b3c485fb851ea15cfdaefb94b9a03fe3a09fd Mon Sep 17 00:00:00 2001 From: Denys Khomenko Date: Thu, 12 Nov 2026 13:24:33 +0200 Subject: [PATCH] Block SIGPIPE only on the OLP SDK cURL worker Blocking SIGPIPE at library load changes the caller's signal mask, which can interfere with unrelated application behavior, including writing to closed pipes. Limit SIGPIPE blocking to the SDK cURL worker so the application thread that loads the SDK keeps its existing signal mask. Relates-To: DATASDK-112 Signed-off-by: Denys Khomenko --- .../src/http/curl/NetworkCurl.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp b/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp index 3296e4af1..4b60bfda1 100644 --- a/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp +++ b/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp @@ -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; @@ -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 @@ -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); {