Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix %err_code/%err_detail for some error:transaction-end-before-headers #270

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 36 additions & 41 deletions src/client_side.cc
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,7 @@ ConnStateData::swanSong()
flags.readMore = false;
clientdbEstablished(clientConnection->remote, -1); /* decrement */

terminateAll(ERR_NONE, LogTagsErrors());
checkLogging();
terminateAll(ERR_STREAM_FAILURE, LogTagsErrors());

// XXX: Closing pinned conn is too harsh: The Client may want to continue!
unpinConnection(true);
Expand Down Expand Up @@ -3904,63 +3903,59 @@ ConnStateData::unpinConnection(const bool andClose)
void
ConnStateData::terminateAll(const Error &rawError, const LogTagsErrors &lte)
{
Assure(rawError);

auto error = rawError; // (cheap) copy so that we can detail
// We detail even ERR_NONE: There should be no transactions left, and
// detailed ERR_NONE will be unused. Otherwise, this detail helps in triage.
if (error.details.empty()) {
static const auto d = MakeNamedErrorDetail("WITH_CLIENT");
error.details.push_back(d);
}

debugs(33, 3, pipeline.count() << '/' << pipeline.nrequests << " after " << error);

if (pipeline.empty()) {
bareError.update(error); // XXX: bareLogTagsErrors
} else {
// We terminate the current CONNECT/PUT/etc. context below, logging any
// error details, but that context may leave unparsed bytes behind.
// Consume them to stop checkLogging() from logging them again later.
const auto intputToConsume =
#if USE_OPENSSL
parsingTlsHandshake ? "TLS handshake" : // more specific than CONNECT
#endif
bodyPipe ? "HTTP request body" :
pipeline.back()->mayUseConnection() ? "HTTP CONNECT" :
nullptr;

while (const auto context = pipeline.front()) {
context->noteIoError(error, lte);
context->finished(); // cleanup and self-deregister
assert(context != pipeline.front());
}
const auto leftovers = handleLeftovers();

while (const auto context = pipeline.front()) {
context->noteIoError(error, lte);
context->finished(); // cleanup and self-deregister
assert(context != pipeline.front());
}

if (intputToConsume && !inBuf.isEmpty()) {
debugs(83, 5, "forgetting client " << intputToConsume << " bytes: " << inBuf.length());
inBuf.clear();
if (!terminatedAll) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag prevents from logging twice a transaction with zero bytes (!pipeline.nrequests is true). The second terminateAll() call is from swanSong(). We could also reset inBuf below (so that leftovers would be false upon the second call).

if (leftovers || !pipeline.nrequests) {
/* Create a temporary ClientHttpRequest object. Its destructor will log. */
ClientHttpRequest http(this);
http.req_sz = inBuf.length();
// XXX: Or we died while waiting for the pinned connection to become idle.
http.setErrorUri("error:transaction-end-before-headers");
http.updateError(error);
}
}

terminatedAll = true;

clientConnection->close();
}

/// log the last (attempt at) transaction if nobody else did
void
ConnStateData::checkLogging()
/// whether we should ignore unparsed inBuf bytes
/// during transaction termination
bool
ConnStateData::handleLeftovers()
{
// to simplify our logic, we assume that terminateAll() has been called
assert(pipeline.empty());
const auto intputToConsume =
#if USE_OPENSSL
parsingTlsHandshake ? "TLS handshake" : // more specific than CONNECT
#endif
bodyPipe ? "HTTP request body" :
(!pipeline.empty() && pipeline.back()->mayUseConnection()) ? "HTTP CONNECT" :
nullptr;

// do not log connections that closed after a transaction (it is normal)
// TODO: access_log needs ACLs to match received-no-bytes connections
if (pipeline.nrequests && inBuf.isEmpty())
return;
if (intputToConsume && !inBuf.isEmpty()) {
debugs(83, 5, "forgetting client " << intputToConsume << " bytes: " << inBuf.length());
inBuf.clear();
}

/* Create a temporary ClientHttpRequest object. Its destructor will log. */
ClientHttpRequest http(this);
http.req_sz = inBuf.length();
// XXX: Or we died while waiting for the pinned connection to become idle.
http.setErrorUri("error:transaction-end-before-headers");
http.updateError(bareError);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like bareError became used after removing checkLogging() - we can probably remove it too.

return !inBuf.isEmpty();
}

bool
Expand Down
4 changes: 3 additions & 1 deletion src/client_side.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class ConnStateData:
void terminateAll(const Error &, const LogTagsErrors &) override;
bool shouldCloseOnEof() const override;

void checkLogging();
bool handleLeftovers();

void parseRequests();
void clientAfterReadingRequests();
Expand Down Expand Up @@ -503,6 +503,8 @@ class ConnStateData:
/// If set, are propagated to the current and all future master transactions
/// on the connection.
NotePairs::Pointer theNotes;
/// whether terminateAll() has been called
bool terminatedAll = false;
};

const char *findTrailingHTTPVersion(const char *uriAndHTTPVersion, const char *end = nullptr);
Expand Down
1 change: 1 addition & 0 deletions src/error/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ typedef enum {
ERR_REQUEST_START_TIMEOUT, // Aborts the connection instead of error page
ERR_REQUEST_PARSE_TIMEOUT, // Aborts the connection instead of error page
ERR_RELAY_REMOTE, // Sends server reply instead of error page
ERR_STREAM_FAILURE, // No client to send the error page to

/* Cache Manager GUI can install a manager index/home page */
MGR_INDEX,
Expand Down