diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc index fb306a7f6b3..610c1960c0f 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 @@ -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) {