This is an automated email from the ASF dual-hosted git repository.

mochen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new a5363d2adc Error messages when server closes connection (#12437)
a5363d2adc is described below

commit a5363d2adcb76add48553127bd23f18e3d49286b
Author: Mo Chen <[email protected]>
AuthorDate: Wed Jan 14 10:35:10 2026 -0600

    Error messages when server closes connection (#12437)
    
    A server can close a connection while we're expecting a response.  For 
example, the server may close the connection due to a keep-alive timeout.  This 
results in a 502 response to the client.  Log an error in this case, so that 
the administrator has a chance to adjust the keep-alive timeout on the ATS side 
to avoid this situation.
---
 src/proxy/http/HttpSM.cc | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc
index 87e8c85945..0a9ed2c994 100644
--- a/src/proxy/http/HttpSM.cc
+++ b/src/proxy/http/HttpSM.cc
@@ -142,6 +142,31 @@ std::atomic<int64_t> next_sm_id(0);
 /// Buffer for some error logs.
 thread_local std::string error_bw_buffer;
 
+constexpr size_t ORIGIN_LOG_URL_LEN = 512;
+
+void
+log_server_close_with_origin(HttpTransact::State &state, const char *message)
+{
+  if (message == nullptr) {
+    return;
+  }
+
+  if (state.hdr_info.server_request.valid()) {
+    char origin_url[ORIGIN_LOG_URL_LEN] = {0};
+    int  offset                         = 0;
+    int  skip                           = 0;
+
+    state.hdr_info.server_request.url_print(origin_url, 
static_cast<int>(ORIGIN_LOG_URL_LEN) - 1, &offset, &skip);
+    if (offset > 0) {
+      origin_url[offset] = '\0';
+      Log::error("%s (origin %s)", message, origin_url);
+      return;
+    }
+  }
+
+  Log::error("%s", message);
+}
+
 } // namespace
 
 int64_t
@@ -1945,6 +1970,7 @@ HttpSM::state_read_server_response_header(int event, void 
*data)
 
   switch (event) {
   case VC_EVENT_EOS:
+    log_server_close_with_origin(t_state, "Server closed connection while 
reading response header.");
     server_entry->eos = true;
     // If we have received any bytes for this transaction do not retry
     if (server_response_hdr_bytes > 0) {

Reply via email to