Skip to content

[BUG] Embedded HTTP server (ext/http) closes connections on transient nonblocking recv errors #4282

Closed as not planned

Description

@thc1006

What

HttpServer::onSocketReadable() in ext/include/opentelemetry/ext/http/server/http_server.h treats every non-positive recv() result as a closed connection:

int received = socket.recv(buffer, sizeof(buffer));
LOG_TRACE(..., received);
if (received <= 0)
{
  handleConnectionClosed(conn);
  return;
}

For a nonblocking socket, recv() returning -1 with EWOULDBLOCK/EAGAIN is a transient condition meaning "no data available yet", not a closed connection. Only recv() == 0 is an orderly shutdown by the peer. The current code closes the connection on any transient -1, which can drop otherwise-healthy connections whenever a readable event fires without data still buffered.

Related: error code read after logging

As in the send path, the error code should be captured immediately after recv(), before LOG_TRACE can clobber errno / the Winsock last error.

Suggested fix

Distinguish the three cases and capture the error before logging:

int received  = socket.recv(...);
int recvError = (received < 0) ? socket.error() : 0;
LOG_TRACE(..., received);
if (received > 0)
{
  // append + handle
}
else if (received == 0)
{
  handleConnectionClosed(conn);   // orderly shutdown
}
else if (recvError != ErrorWouldBlock && recvError != ErrorAgain)
{
  handleConnectionClosed(conn);   // a real error; transient would-block retries on the next event
}

Found while reviewing #4280. A PR will follow.

Activity

  1. added
    needs-triage
    on Jul 23, 2026
  2. added 6 commits that reference this issue on Jul 23, 2026
    d294ce8
    3af9f11
    171b8e0
    84d5411
    b48b268
    817f73e
  3. thc1006 commented on Aug 3, 2026

    @thc1006
    MemberAuthor

    Closing after @dbarker set the scope for these files on #4287. http_server.h and socket_tools.h are internal, supporting the tests and a single example, and the bar for them is being correct enough for that rather than production hardening. #4283, which would have fixed this, is closed for the same reason. Easy to reopen if it ever shows up in the tests or the example.

  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