Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/majordomo/include/majordomo/Broker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/rest/include/rest/RestUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <nghttp2/nghttp2.h>
#include <nghttp3/nghttp3.h>

#include <signal.h>

#ifdef OPENCMW_DEBUG_HTTP
#include <iostream>
#define HTTP_DBG(...) std::println(std::cerr, __VA_ARGS__);
Expand Down Expand Up @@ -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