]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Improve ErrorState debugging (#1768)
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 5 Jun 2024 18:55:06 +0000 (18:55 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Wed, 5 Jun 2024 22:56:18 +0000 (22:56 +0000)
In triage, it is often useful to know that ErrorState was created _when_
it was created rather than waiting for errorAppendEntry() or errorSend()
debugging, especially if those error handling stages are not reached.

Also report HTTP status code of the error response (when available).

src/FwdState.cc
src/errorpage.cc

index 1e2eb30ae572b6c9ba49af57dfbcd96f122aef63..bac0aa5df87143c60901b2305edcbd86efbcdabc 100644 (file)
@@ -456,7 +456,7 @@ FwdState::useDestinations()
 void
 FwdState::fail(ErrorState * errorState)
 {
-    debugs(17, 3, err_type_str[errorState->type] << " \"" << Http::StatusCodeString(errorState->httpStatus) << "\"\n\t" << entry->url());
+    debugs(17, 3, errorState << "; was: " << err);
 
     delete err;
     err = errorState;
index c01a2c4365ec6150ed43011a46429528d9195e0a..de019667325385690fb9f89302ebe0e92b022718 100644 (file)
@@ -677,6 +677,16 @@ errorPageName(int pageId)
     return "ERR_UNKNOWN";   /* should not happen */
 }
 
+/// compactly prints top-level ErrorState information (for debugging)
+static std::ostream &
+operator <<(std::ostream &os, const ErrorState &err)
+{
+    os << errorPageName(err.type);
+    if (err.httpStatus != Http::scNone)
+        os << "/http_status=" << err.httpStatus;
+    return os;
+}
+
 ErrorState *
 ErrorState::NewForwarding(err_type type, HttpRequestPointer &request, const AccessLogEntry::Pointer &ale)
 {
@@ -705,6 +715,8 @@ ErrorState::ErrorState(err_type t, Http::StatusCode status, HttpRequest * req, c
         request = req;
         src_addr = req->client_addr;
     }
+
+    debugs(4, 3, "constructed, this=" << static_cast<void*>(this) << ' ' << *this);
 }
 
 ErrorState::ErrorState(HttpRequest * req, HttpReply *errorReply, const AccessLogEntry::Pointer &anAle):
@@ -718,6 +730,8 @@ ErrorState::ErrorState(HttpRequest * req, HttpReply *errorReply, const AccessLog
         request = req;
         src_addr = req->client_addr;
     }
+
+    debugs(4, 3, "constructed, this=" << static_cast<void*>(this) << " relaying " << *this);
 }
 
 void
@@ -796,6 +810,8 @@ errorSendComplete(const Comm::ConnectionPointer &conn, char *, size_t size, Comm
 
 ErrorState::~ErrorState()
 {
+    debugs(4, 7, "destructing, this=" << static_cast<void*>(this));
+
     safe_free(redirect_url);
     safe_free(url);
     safe_free(request_hdrs);
@@ -1527,10 +1543,7 @@ ErrorPage::ValidateStaticError(const int page_id, const SBuf &inputLocation)
 std::ostream &
 operator <<(std::ostream &os, const ErrorState *err)
 {
-    if (err)
-        os << errorPageName(err->page_id);
-    else
-        os << "[none]";
+    os << RawPointer(err).orNil();
     return os;
 }