Skip to content

[BUG] Embedded HTTP server writes can raise SIGPIPE and terminate the process #4293

Closed as not planned

Description

@thc1006

Part of #4287.

Socket::send() passes a flags argument of 0:

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));
}

There is no MSG_NOSIGNAL and no SO_NOSIGPIPE anywhere under ext/.

POSIX specifies that a write to a connected socket that can no longer transmit raises SIGPIPE as well as failing with EPIPE, unless the write suppresses it. The default disposition of SIGPIPE terminates the process, so an embedded server whose peer has gone away can take the host process down before any of the error handling in sendMore() runs.

Reproduced on Linux with a socketpair() whose peer end is closed, forking once per flag value:

  flags = 0             -> KILLED by signal 13 (Broken pipe)
  flags = MSG_NOSIGNAL  -> exited 0

Suggested fix

Handle it inside Socket::send() rather than changing the host process signal disposition, since a library should not be deciding that for the program that embeds it.

  • Linux and other platforms that define MSG_NOSIGNAL: pass it per call.
  • macOS and BSD, which offer SO_NOSIGPIPE instead: set the socket option once, at socket creation and again on the socket returned by accept().
  • Windows: nothing to do, there is no SIGPIPE.

Worth doing before the fatal send error item in #4287, because otherwise the process can die before that error handling is ever reached.

I would like to work on this one.

Activity

  1. added
    needs-triage
    on Jul 24, 2026
  2. added a commit that references this issue on Jul 25, 2026
    09044b2
  3. thc1006 commented on Aug 3, 2026

    @thc1006
    MemberAuthor

    Closing after @dbarker set the scope for these files on #4287, same reasoning as #4281 and #4282: socket_tools.h is internal and the bar for it is the tests and the example. #4294 is closed for the same reason. Recording one fact without arguing for it, since it bears on where that bar sits: an unhandled SIGPIPE ends the process rather than failing the call. I have not seen it happen in CI.

  4. added
    triage/not-a-bug
    and removed
    needs-triage
    on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage/not-a-bug

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions