You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Embedded HTTP server (ext/http) closes connections on transient nonblocking recv errors #4282
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
}
elseif (received == 0)
{
handleConnectionClosed(conn); // orderly shutdown
}
elseif (recvError != ErrorWouldBlock && recvError != ErrorAgain)
{
handleConnectionClosed(conn); // a real error; transient would-block retries on the next event
}
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.
Activity
[BUG] Fix nonblocking send/recv handling in the ext/http embedded server
[BUG] Fix nonblocking send/recv handling in the ext/http embedded server
[BUG] Fix nonblocking send/recv handling in the ext/http embedded server
[BUG] Fix nonblocking send/recv handling in the ext/http embedded server
[BUG] Fix nonblocking send/recv handling in the ext/http embedded server
[BUG] Fix nonblocking send/recv handling in the ext/http embedded server
thc1006 commentedon Aug 3, 2026
Closing after @dbarker set the scope for these files on #4287.
http_server.handsocket_tools.hare 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.