Skip to content

Commit

Permalink
Refine sigpipe handling (milvus-io#24872)
Browse files Browse the repository at this point in the history
Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
  • Loading branch information
congqixia authored and luzhang committed Jun 14, 2023
1 parent 3c80f8b commit a2ea420
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/milvus/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"io"
"os"
"os/signal"
"syscall"

"go.uber.org/zap"

Expand Down Expand Up @@ -50,6 +52,9 @@ func (c *run) execute(args []string, flags *flag.FlagSet) {
c.serverType = args[2]
c.formatFlags(args, flags)

// make go ignore SIGPIPE when all cgo threads set mask of SIGPIPE
signal.Ignore(syscall.SIGPIPE)

var local = false
role := roles.MilvusRoles{}
switch c.serverType {
Expand Down
17 changes: 13 additions & 4 deletions internal/core/src/storage/MinioChunkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ std::mutex MinioChunkManager::client_mutex_;

static void
SwallowHandler(int signal) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
switch (signal) {
case SIGPIPE:
LOG_SERVER_WARNING_ << "SIGPIPE Swallowed" << std::endl;
// cannot use log or stdio
write(1, "SIGPIPE Swallowed\n", 18);
break;
default:
LOG_SERVER_ERROR_
<< "Unexpected signal in SIGPIPE handler: " << signal
<< std::endl;
// cannot use log or stdio
write(2, "Unexpected signal\n", 18);
}
#pragma GCC diagnostic pop
}

/**
Expand Down Expand Up @@ -95,6 +98,10 @@ MinioChunkManager::InitSDKAPI(RemoteStorageType type) {
psa.sa_handler = SwallowHandler;
psa.sa_flags = psa.sa_flags | SA_ONSTACK;
sigaction(SIGPIPE, &psa, 0);
// block multiple SIGPIPE concurrently processing
sigemptyset(&psa.sa_mask);
sigaddset(&psa.sa_mask, SIGPIPE);
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();
Expand All @@ -105,6 +112,8 @@ MinioChunkManager::InitSDKAPI(RemoteStorageType type) {
GOOGLE_CLIENT_FACTORY_ALLOCATION_TAG, credentials);
};
}
sdk_options_.loggingOptions.logLevel =
Aws::Utils::Logging::LogLevel::Info;
Aws::InitAPI(sdk_options_);
}
}
Expand Down

0 comments on commit a2ea420

Please sign in to comment.