Skip to content

Commit fbb9387

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 1241565 commit fbb9387

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
@@ -984,14 +984,10 @@ struct GzipEventHandler : public CustomEventHandler
984984
std::string reason_;
985985
};
986986

987-
// A request whose compression step fails is reported as a failed create and then must not be
988-
// sent. It used to be reported and sent anyway, with a body the failed deflate had already
989-
// partly rewritten and no Content-Encoding header to describe it.
987+
// A request whose compression step fails reports CreateFailed and is not sent.
990988
//
991-
// The failure is arranged rather than injected. deflateInPlace() is given the body's own size as
992-
// its output budget, and its comment says it fails when that budget is smaller than the header
993-
// plus one byte, so a body of one byte cannot fit a gzip header and the deflate reports
994-
// Z_BUF_ERROR. No allocator hook and no timing are involved.
989+
// The failure is arranged, not injected: deflateInPlace() gets the body's own size as its output
990+
// budget, and one byte cannot hold a gzip header, so it returns Z_BUF_ERROR.
995991
TEST_F(BasicCurlHttpTests, AFailedCompressionStopsTheRequest)
996992
{
997993
received_requests_.clear();
@@ -1118,17 +1114,8 @@ TEST_F(BasicCurlHttpTests, GzipIncompressibleData)
11181114
auto handler = std::make_shared<GzipEventHandler>();
11191115
session->SendRequest(handler);
11201116

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

0 commit comments

Comments
 (0)