Skip to content

Commit 76120d2

Browse files
committed
[CHORE] Shorten the comments to what the code does not already say
The comments on the failure path explained how the code came to be shaped that way. That belongs in this PR and in the commit history, not beside the code, and it left nine lines of comment against seven of code. What is left is the two things a reader cannot get from the code: why the reason is copied before deflateEnd(), and why nothing may touch the session after the handler runs. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
1 parent b5776ee commit 76120d2

2 files changed

Lines changed: 10 additions & 26 deletions

File tree

‎ext/src/http/client/curl/http_client_curl.cc‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,21 @@ void Session::SendRequest(
184184

185185
if (stream != Z_OK)
186186
{
187-
// Taken before deflateEnd(), which releases what zs.msg points at.
187+
// zs.msg points into the stream deflateEnd() releases.
188188
const std::string reason = (nullptr != zs.msg) ? zs.msg : "";
189189
deflateEnd(&zs);
190190

191-
// Before the handler runs, because the handler is application code: it can start another
192-
// request on this session or drop the last reference to it, and nothing below this point
193-
// may touch the session afterwards.
191+
// The handler may start another request on this session or drop the last reference to it,
192+
// so nothing below this point may touch the session.
194193
is_session_active_.store(false, std::memory_order_release);
195194

196195
if (callback)
197196
{
198197
callback->OnEvent(opentelemetry::ext::http::client::SessionState::CreateFailed, reason);
199198
}
200199

201-
// The caller has been told this request failed, so it does not go out. The body has also
202-
// been partly rewritten in place by the deflate that failed and carries no Content-Encoding
203-
// header, so what would have been sent is neither what the caller asked for nor readable as
204-
// gzip at the other end.
200+
// deflateInPlace() rewrote part of the body before reporting that it would not fit, and no
201+
// Content-Encoding header describes what is left. The request does not go out.
205202
return;
206203
}
207204

‎ext/test/http/curl_http_test.cc‎

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -991,14 +991,10 @@ struct GzipEventHandler : public CustomEventHandler
991991
std::string reason_;
992992
};
993993

994-
// A request whose compression step fails is reported as a failed create and then must not be
995-
// sent. It used to be reported and sent anyway, with a body the failed deflate had already
996-
// partly rewritten and no Content-Encoding header to describe it.
994+
// A request whose compression step fails reports CreateFailed and is not sent.
997995
//
998-
// The failure is arranged rather than injected. deflateInPlace() is given the body's own size as
999-
// its output budget, and its comment says it fails when that budget is smaller than the header
1000-
// plus one byte, so a body of one byte cannot fit a gzip header and the deflate reports
1001-
// Z_BUF_ERROR. No allocator hook and no timing are involved.
996+
// The failure is arranged, not injected: deflateInPlace() gets the body's own size as its output
997+
// budget, and one byte cannot hold a gzip header, so it returns Z_BUF_ERROR.
1002998
TEST_F(BasicCurlHttpTests, AFailedCompressionStopsTheRequest)
1003999
{
10041000
received_requests_.clear();
@@ -1125,17 +1121,8 @@ TEST_F(BasicCurlHttpTests, GzipIncompressibleData)
11251121
auto handler = std::make_shared<GzipEventHandler>();
11261122
session->SendRequest(handler);
11271123

1128-
// This used to require a response, on the reading that data which will not compress is sent
1129-
// uncompressed. The size assertion below is what that rested on, and the size is not the whole
1130-
// story: deflateInPlace() writes into the caller's buffer before it reports that the result
1131-
// would not fit, so the body keeps its length while its contents are no longer the caller's
1132-
// bytes. What went out was neither the payload nor a gzip stream, and carried no
1133-
// Content-Encoding header to describe itself either way.
1134-
//
1135-
// Refusing to send it is the narrow reading of "do not send after reporting a failure". Keeping
1136-
// the payload instead, by compressing into a separate buffer or by restoring the original on
1137-
// failure, would let incompressible data still be sent and costs a copy. That is a decision
1138-
// rather than a repair, so it is #4360 rather than this change.
1124+
// deflateInPlace() overwrites part of the caller's buffer before reporting that the result will
1125+
// not fit, so no payload survives to send uncompressed. Whether to keep one is #4360.
11391126
ASSERT_TRUE(handler->is_called_);
11401127
ASSERT_EQ(handler->state_, http_client::SessionState::CreateFailed);
11411128

0 commit comments

Comments
 (0)