Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
09044b2
[BUG] Stop embedded HTTP server writes from raising SIGPIPE
thc1006 Jul 24, 2026
6970a6e
Add CHANGELOG entry for the SIGPIPE suppression fix
thc1006 Jul 24, 2026
5f6baa3
Do not swallow the SO_NOSIGPIPE setsockopt result
thc1006 Jul 25, 2026
216186f
Add a broken-pipe regression test and scope the SO_NOSIGPIPE claim
thc1006 Jul 25, 2026
19b4660
Apply SO_NOSIGPIPE in the broken-pipe test as production does
thc1006 Jul 25, 2026
9ce1b34
Harden the SIGPIPE test: fixture cleanup, negative control, accept path
thc1006 Jul 25, 2026
68e90a5
Fix CI: IWYU includes, gtest_add_tests, always-compile platform tests
thc1006 Jul 25, 2026
34ef516
Strengthen SIGPIPE tests; fix CMake comment and errno accuracy
thc1006 Jul 25, 2026
a80da53
Force SIGPIPE to SIG_DFL in the SigPipe test fixture SetUp
thc1006 Jul 25, 2026
c08a131
Guard each SIGPIPE signal-behavior test against an inherited SIG_IGN
thc1006 Jul 25, 2026
031fd67
Merge remote-tracking branch 'origin/main' into bugfix/suppress-sigpi…
thc1006 Jul 25, 2026
cf3e961
Address review nits: correct non-owning wording and SIGPIPE-ignore note
thc1006 Jul 26, 2026
d3b4c72
Align GTEST_SKIP messages with the portability rationale
thc1006 Jul 26, 2026
751458b
Fix two baseline-case message contradictions
thc1006 Jul 27, 2026
2e1aef4
Give the raw baseline its own skip/failure wording
thc1006 Jul 27, 2026
b5d4f41
Merge remote-tracking branch 'origin/main' into bugfix/suppress-sigpi…
thc1006 Jul 27, 2026
b29cb83
Merge remote-tracking branch 'origin/main' into bugfix/suppress-sigpi…
thc1006 Jul 29, 2026
4fe3a88
Merge remote-tracking branch 'origin/main' into bugfix/suppress-sigpi…
thc1006 Aug 1, 2026
b2c9c56
Merge remote-tracking branch 'origin/main' into bugfix/suppress-sigpi…
thc1006 Aug 2, 2026
427df5a
Drop an unused include and correct the SO_NOSIGPIPE comment
thc1006 Aug 2, 2026
05792f7
Put <string> back
thc1006 Aug 2, 2026
8dbf12a
Merge branch 'main' into bugfix/suppress-sigpipe-on-send
thc1006 Aug 3, 2026
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Increment the:
* [BUG] Wait on a completion state in the Elasticsearch exporter
[#4298](https://github.com/open-telemetry/opentelemetry-cpp/pull/4298)

* [BUG] Stop embedded HTTP server writes from raising SIGPIPE
[#4294](https://github.com/open-telemetry/opentelemetry-cpp/pull/4294)

* [BUG] Make SocketAddr string parsing safe and reject malformed addresses
[#4292](https://github.com/open-telemetry/opentelemetry-cpp/pull/4292)

Expand Down
43 changes: 41 additions & 2 deletions ext/include/opentelemetry/ext/http/server/socket_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ struct Socket

Socket(Type sock = Invalid) : m_sock(sock) {}

Socket(int af, int type, int proto) : m_sock(::socket(af, type, proto)) {}
Socket(int af, int type, int proto) : m_sock(::socket(af, type, proto)) { suppressSigPipe(); }

operator Socket::Type() const { return m_sock; }

Expand Down Expand Up @@ -401,6 +401,39 @@ struct Socket
m_sock = Invalid;
}

/**
* Stop writes to a socket whose peer has gone away from raising SIGPIPE, whose default
* disposition would terminate the host process. The primary guarantee is MSG_NOSIGNAL, which
* send() passes per call on every platform that defines it. Where the platform also offers
* SO_NOSIGPIPE (macOS, the BSDs) this
* additionally sets it at the socket level as a best-effort second layer, covering a write to
* the descriptor that does not go through send(). Windows has no SIGPIPE. Done per socket rather
* than by changing the process signal disposition, which belongs to the embedding program rather
* than to this library.
*/
void suppressSigPipe()
{
#ifdef SO_NOSIGPIPE
if (m_sock != Invalid)
{
int value = 1;
if (::setsockopt(m_sock, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast<char *>(&value),
sizeof(value)) != 0)
{
// Best effort. On the platforms that offer SO_NOSIGPIPE, macOS chief among them,
// MSG_NOSIGNAL is not defined, so this option is the only mechanism and a failure here
// leaves writes unprotected. It is logged where a logger is configured rather than
// failing the socket, since the caller asked for a socket and not for this guarantee.
// This wrapper does not own the descriptor's lifetime and does not promise to protect a
// platform whose only defence would be SO_NOSIGPIPE.
const int saved_errno = errno; // capture before LOG_WARN, which may clobber errno
LOG_WARN("Socket: cannot set SO_NOSIGPIPE (errno %d)", saved_errno);
static_cast<void>(saved_errno); // LOG_WARN can compile to a no-op
}
}
#endif
}

int recv(void *buffer, unsigned size)
{
assert(m_sock != Invalid);
Expand All @@ -411,7 +444,12 @@ struct Socket
int send(void const *buffer, unsigned size)
{
assert(m_sock != Invalid);
return static_cast<int>(::send(m_sock, reinterpret_cast<char const *>(buffer), size, 0));
#ifdef MSG_NOSIGNAL
int const flags = MSG_NOSIGNAL;
#else
int const flags = 0;
#endif
return static_cast<int>(::send(m_sock, reinterpret_cast<char const *>(buffer), size, flags));
}

bool bind(SocketAddr const &addr)
Expand Down Expand Up @@ -446,6 +484,7 @@ struct Socket
socklen_t addrlen = sizeof(caddr);
#endif
csock = ::accept(m_sock, caddr, &addrlen);
csock.suppressSigPipe();
return !csock.invalid();
}

Expand Down
12 changes: 12 additions & 0 deletions ext/test/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@

load("@rules_cc//cc:cc_test.bzl", "cc_test")

cc_test(
name = "socket_sigpipe_test",
srcs = [
"socket_sigpipe_test.cc",
],
tags = ["test"],
deps = [
"//ext:headers",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "socket_tools_test",
srcs = [
Expand Down
17 changes: 17 additions & 0 deletions ext/test/http/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ if(WITH_HTTP_CLIENT_CURL)
TEST_LIST ${FILENAME})
endif()

# The CMake target is POSIX-only (Windows has no SIGPIPE); the Bazel target
# covers Windows. The platform-dependent tests are declared unconditionally in
# the POSIX source and skip at runtime where their mechanism is unavailable, so
# gtest_add_tests, which scans the source, registers only tests the POSIX binary
# actually contains.
if(NOT WIN32)
set(SOCKET_SIGPIPE_FILENAME socket_sigpipe_test)
add_executable(${SOCKET_SIGPIPE_FILENAME} ${SOCKET_SIGPIPE_FILENAME}.cc)
target_link_libraries(
${SOCKET_SIGPIPE_FILENAME} opentelemetry_ext ${GMOCK_LIB}
${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
gtest_add_tests(
TARGET ${SOCKET_SIGPIPE_FILENAME}
TEST_PREFIX ext.http.socketsigpipe.
TEST_LIST ${SOCKET_SIGPIPE_FILENAME})
endif()

set(SOCKET_TOOLS_FILENAME socket_tools_test)
add_executable(${SOCKET_TOOLS_FILENAME} ${SOCKET_TOOLS_FILENAME}.cc)
target_link_libraries(${SOCKET_TOOLS_FILENAME} opentelemetry_ext ${GMOCK_LIB}
Expand Down
Loading
Loading