From 73a5081a4a22e09beb40503d3b3d2cd0cf28c87c Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Thu, 7 Aug 2025 14:08:00 -0500 Subject: [PATCH 1/6] Error messages when server closes connection 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc index dae99d76a3a..50e16d02e57 100644 --- a/src/proxy/http/HttpSM.cc +++ b/src/proxy/http/HttpSM.cc @@ -1003,6 +1003,7 @@ HttpSM::state_read_push_response_header(int event, void *data) switch (event) { case VC_EVENT_EOS: _ua.get_entry()->eos = true; + Error("Server closed connection while reading PUSH response header."); // Fall through case VC_EVENT_READ_READY: @@ -1932,6 +1933,7 @@ HttpSM::state_read_server_response_header(int event, void *data) switch (event) { case VC_EVENT_EOS: + Error("Server closed connection while reading response header"); server_entry->eos = true; // Fall through From 120b48d2dea718b5f6a534f697e03a88d6baa7fd Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Mon, 11 Aug 2025 15:58:43 -0500 Subject: [PATCH 2/6] Use Log::error instead of Error --- src/proxy/http/HttpSM.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc index 50e16d02e57..73c3209ed69 100644 --- a/src/proxy/http/HttpSM.cc +++ b/src/proxy/http/HttpSM.cc @@ -1003,7 +1003,7 @@ HttpSM::state_read_push_response_header(int event, void *data) switch (event) { case VC_EVENT_EOS: _ua.get_entry()->eos = true; - Error("Server closed connection while reading PUSH response header."); + Log::error("Server closed connection while reading PUSH response header."); // Fall through case VC_EVENT_READ_READY: @@ -1933,7 +1933,7 @@ HttpSM::state_read_server_response_header(int event, void *data) switch (event) { case VC_EVENT_EOS: - Error("Server closed connection while reading response header"); + Log::error("Server closed connection while reading response header"); server_entry->eos = true; // Fall through From ffa02645549280224c4afda076833ed7d3aa2a73 Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Tue, 11 Nov 2025 12:23:35 -0600 Subject: [PATCH 3/6] Add url to error printout --- src/proxy/http/HttpSM.cc | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc index 73c3209ed69..459f2760316 100644 --- a/src/proxy/http/HttpSM.cc +++ b/src/proxy/http/HttpSM.cc @@ -142,6 +142,31 @@ std::atomic 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(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 @@ -1001,9 +1026,10 @@ HttpSM::state_read_push_response_header(int event, void *data) ink_assert(t_state.current.server == nullptr); switch (event) { - case VC_EVENT_EOS: + case VC_EVENT_EOS: { _ua.get_entry()->eos = true; - Log::error("Server closed connection while reading PUSH response header."); + log_server_close_with_origin(t_state, "Server closed connection while reading PUSH response header."); + } // Fall through case VC_EVENT_READ_READY: @@ -1932,9 +1958,10 @@ HttpSM::state_read_server_response_header(int event, void *data) int bytes_used = 0; switch (event) { - case VC_EVENT_EOS: - Log::error("Server closed connection while reading response header"); + case VC_EVENT_EOS: { + log_server_close_with_origin(t_state, "Server closed connection while reading response header"); server_entry->eos = true; + } // Fall through case VC_EVENT_READ_READY: From 34ae6fa498d63ab057c5f5f6f683ee2ecb5d6ab5 Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Fri, 21 Nov 2025 14:06:12 -0600 Subject: [PATCH 4/6] Consistent formatting --- src/proxy/http/HttpSM.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc index 217de50dd7a..e8825004ae5 100644 --- a/src/proxy/http/HttpSM.cc +++ b/src/proxy/http/HttpSM.cc @@ -1032,10 +1032,9 @@ HttpSM::state_read_push_response_header(int event, void *data) ink_assert(t_state.current.server == nullptr); switch (event) { - case VC_EVENT_EOS: { + case VC_EVENT_EOS: _ua.get_entry()->eos = true; log_server_close_with_origin(t_state, "Server closed connection while reading PUSH response header."); - } // Fall through case VC_EVENT_READ_READY: From c2ef333078cd84ffe89d610b2dd0ad63a19def73 Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Fri, 21 Nov 2025 14:07:17 -0600 Subject: [PATCH 5/6] Consistent code order --- src/proxy/http/HttpSM.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc index e8825004ae5..ddf28507e10 100644 --- a/src/proxy/http/HttpSM.cc +++ b/src/proxy/http/HttpSM.cc @@ -1033,8 +1033,8 @@ HttpSM::state_read_push_response_header(int event, void *data) switch (event) { case VC_EVENT_EOS: - _ua.get_entry()->eos = true; log_server_close_with_origin(t_state, "Server closed connection while reading PUSH response header."); + _ua.get_entry()->eos = true; // Fall through case VC_EVENT_READ_READY: From c2dc8e7cc5065e5bd7a3e51e4007d9a826e191b9 Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Mon, 1 Dec 2025 15:28:59 -0600 Subject: [PATCH 6/6] Add missing period. Remove PUSH message. --- src/proxy/http/HttpSM.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc index ddf28507e10..610c1960c0f 100644 --- a/src/proxy/http/HttpSM.cc +++ b/src/proxy/http/HttpSM.cc @@ -1033,7 +1033,6 @@ HttpSM::state_read_push_response_header(int event, void *data) switch (event) { case VC_EVENT_EOS: - log_server_close_with_origin(t_state, "Server closed connection while reading PUSH response header."); _ua.get_entry()->eos = true; // Fall through @@ -1971,7 +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"); + 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) {