From e729b504aba0d8dacd87b656718d5c1b51dfcd1d Mon Sep 17 00:00:00 2001 From: congqixia Date: Thu, 8 Jun 2023 15:50:35 +0800 Subject: [PATCH] Use SA_ONSTACK flag for SIGPIPE handler (#24688) Signed-off-by: Congqi Xia --- .../core/src/storage/MinioChunkManager.cpp | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/internal/core/src/storage/MinioChunkManager.cpp b/internal/core/src/storage/MinioChunkManager.cpp index 887d6c6b48..d795465bb5 100644 --- a/internal/core/src/storage/MinioChunkManager.cpp +++ b/internal/core/src/storage/MinioChunkManager.cpp @@ -14,8 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "storage/MinioChunkManager.h" - +#include #include #include #include @@ -28,12 +27,12 @@ #include #include -#include - +#include "storage/MinioChunkManager.h" #include "storage/AliyunSTSClient.h" #include "storage/AliyunCredentialsProvider.h" #include "exceptions/EasyAssert.h" #include "log/Log.h" +#include "signal.h" #define THROWS3ERROR(FUNCTION) \ do { \ @@ -50,6 +49,19 @@ namespace milvus::storage { std::atomic MinioChunkManager::init_count_(0); std::mutex MinioChunkManager::client_mutex_; +static void +SwallowHandler(int signal) { + switch (signal) { + case SIGPIPE: + LOG_SERVER_WARNING_ << "SIGPIPE Swallowed" << std::endl; + break; + default: + LOG_SERVER_ERROR_ + << "Unexpected signal in SIGPIPE handler: " << signal + << std::endl; + } +} + /** * @brief convert std::string to Aws::String * because Aws has String type internally @@ -78,7 +90,11 @@ MinioChunkManager::InitSDKAPI(RemoteStorageType type) { std::scoped_lock lock{client_mutex_}; const size_t initCount = init_count_++; if (initCount == 0) { - sdk_options_.httpOptions.installSigPipeHandler = true; + // sdk_options_.httpOptions.installSigPipeHandler = true; + struct sigaction psa; + psa.sa_handler = SwallowHandler; + psa.sa_flags = psa.sa_flags | SA_ONSTACK; + sigaction(SIGPIPE, &psa, 0); if (type == RemoteStorageType::GOOGLE_CLOUD) { sdk_options_.httpOptions.httpClientFactory_create_fn = []() { // auto credentials = google::cloud::oauth2_internal::GOOGLE_CLOUD_CPP_NS::GoogleDefaultCredentials();