diff --git a/src/majordomo/include/majordomo/Broker.hpp b/src/majordomo/include/majordomo/Broker.hpp index f5c35ea6..c0c9e73c 100644 --- a/src/majordomo/include/majordomo/Broker.hpp +++ b/src/majordomo/include/majordomo/Broker.hpp @@ -301,6 +301,8 @@ class Broker { , _subSocket(context, ZMQ_SUB) , _dnsSocket(context, ZMQ_DEALER) { assert(mdp::isValidServiceName(brokerName)); + + opencmw::rest::detail::setupIgnoreSigpipe(); addInternalService("/mmi.dns", [this](BrokerMessage &&message) { using namespace std::literals; diff --git a/src/rest/include/rest/RestUtils.hpp b/src/rest/include/rest/RestUtils.hpp index 9e4f1425..f7b800a3 100644 --- a/src/rest/include/rest/RestUtils.hpp +++ b/src/rest/include/rest/RestUtils.hpp @@ -29,6 +29,8 @@ #include #include +#include + #ifdef OPENCMW_DEBUG_HTTP #include #define HTTP_DBG(...) std::println(std::cerr, __VA_ARGS__); @@ -468,6 +470,23 @@ struct WriteBuffer { } }; + +// Temporary SIGPIPE mitigation. We currently intercept SIGPIPE to prevent the process from terminating on broken sockets +// (e.g. client aborts during TLS/HTTP write). Revisit this later and decide on the final production behavior. +inline void sigpipeHandler(int) { + const char msg[] = "opencmw: SIGPIPE. Usually caused by client disconnect/reset during TLS/HTTP write.\n"; + ::write(STDERR_FILENO, msg, sizeof(msg) - 1); +} + +inline void setupIgnoreSigpipe() { + struct sigaction sa {}; + sa.sa_handler = sigpipeHandler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + ::sigaction(SIGPIPE, &sa, nullptr); +} + + } // namespace opencmw::rest::detail #endif