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) drops the pending response when a nonblocking send would block #4281
HttpServer::sendMore() in ext/include/opentelemetry/ext/http/server/http_server.h mishandles a nonblocking send() that returns -1 with EWOULDBLOCK/EAGAIN:
int sent = conn.socket.send(...);
LOG_TRACE(..., sent);
if (sent < 0 && conn.socket.error() != SocketTools::Socket::ErrorWouldBlock)
{
returntrue;
}
conn.sendBuffer.erase(0, sent); // sent == -1 -> erase(0, (size_t)-1) wipes the whole buffer
When the socket is not writable (backpressure), send() returns -1 with EWOULDBLOCK. The early return is skipped, because its condition requires the error to not be would-block, so control falls through to erase(0, sent) with sent == -1. std::string::erase(pos, count) takes count as size_type, so -1 becomes SIZE_MAX and the entire sendBuffer is erased. The unsent part of the HTTP response is silently lost, and because the buffer is now empty the connection is treated as if the response was fully sent.
Related: error code read after logging
conn.socket.error() (which reads errno on POSIX / WSAGetLastError() on Windows) is evaluated afterLOG_TRACE, which may call printf and clobber the error code. WSAGetLastError() in particular is documented to be read immediately after the failing socket call. The error should be captured right after send().
Impact
Truncated or lost HTTP responses under write backpressure in the embedded server. It is a mock server ("out of scope: performance"), so this mostly affects larger responses on slow or full sockets, but it is a correctness bug and this header is installed with opentelemetry_ext.
Suggested fix
Capture the error before logging, never erase on sent < 0, and re-register for writability on a genuine would-block:
int sent = conn.socket.send(...);
int sendError = (sent < 0) ? conn.socket.error() : 0;
LOG_TRACE(..., sent);
if (sent < 0)
{
if (sendError == ErrorWouldBlock || sendError == ErrorAgain)
{
m_reactor.addSocket(conn.socket, Writable | Closed); // keep the buffer, wait for writability
}
returntrue;
}
conn.sendBuffer.erase(0, static_cast<size_t>(sent));
EAGAIN and EWOULDBLOCK may be distinct values on some POSIX systems, and Socket currently only defines ErrorWouldBlock, so an ErrorAgain alias is also needed.
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.