2424
2525#include " proxy/http/HttpConfig.h"
2626#include " tscore/ink_hrtime.h"
27+ #include " tscore/ink_time.h"
2728#include " tsutil/Metrics.h"
2829#include " tsutil/ts_bw_format.h"
2930#include " proxy/ProxyTransaction.h"
@@ -4731,9 +4732,12 @@ HttpSM::do_hostdb_update_if_necessary()
47314732 t_state.dns_info .active ->http_version = t_state.updated_server_version ;
47324733 }
47334734
4735+ char addrbuf[INET6_ADDRPORTSTRLEN];
4736+ SMDbg (dbg_ctl_http, " update hostdb info: %s" , ats_ip_nptop (&t_state.current .server ->dst_addr .sa , addrbuf, sizeof (addrbuf)));
4737+
47344738 // Check to see if we need to report or clear a connection failure
47354739 if (track_connect_fail ()) {
4736- this ->mark_host_failure (&t_state.dns_info , ts_clock::from_time_t (t_state. client_request_time ));
4740+ this ->mark_host_failure (&t_state.dns_info , ts_clock::now ( ));
47374741 } else {
47384742 if (t_state.dns_info .mark_active_server_up ()) {
47394743 char addrbuf[INET6_ADDRPORTSTRLEN];
@@ -4748,8 +4752,6 @@ HttpSM::do_hostdb_update_if_necessary()
47484752 }
47494753 }
47504754
4751- char addrbuf[INET6_ADDRPORTSTRLEN];
4752- SMDbg (dbg_ctl_http, " server info = %s" , ats_ip_nptop (&t_state.current .server ->dst_addr .sa , addrbuf, sizeof (addrbuf)));
47534755 return ;
47544756}
47554757
@@ -5521,12 +5523,6 @@ HttpSM::do_http_server_open(bool raw, bool only_direct)
55215523 return ;
55225524 }
55235525 }
5524- if (HttpTransact::is_server_negative_cached (&t_state) == true &&
5525- t_state.txn_conf ->connect_attempts_max_retries_down_server <= 0 ) {
5526- SMDbg (dbg_ctl_http_seq, " Not connecting to the server because it is marked down." );
5527- call_transact_and_set_next_state (HttpTransact::OriginDown);
5528- return ;
5529- }
55305526
55315527 // Check for self loop.
55325528 if (!_ua.get_txn ()->is_outbound_transparent () && HttpTransact::will_this_request_self_loop (&t_state)) {
@@ -5972,34 +5968,35 @@ HttpSM::do_transform_open()
59725968void
59735969HttpSM::mark_host_failure (ResolveInfo *info, ts_time time_down)
59745970{
5975- char addrbuf[INET6_ADDRPORTSTRLEN] ;
5971+ ink_assert (time_down != TS_TIME_ZERO) ;
59765972
5977- if (info->active ) {
5978- if (time_down != TS_TIME_ZERO) {
5979- ats_ip_nptop (&t_state.current .server ->dst_addr .sa , addrbuf, sizeof (addrbuf));
5980- // Increment the fail_count
5981- if (auto [down, fail_count] = info->active ->increment_fail_count (time_down, t_state.txn_conf ->connect_attempts_rr_retries ,
5982- t_state.txn_conf ->down_server_timeout );
5983- down) {
5984- char *url_str = t_state.hdr_info .client_request .url_string_get_ref (nullptr );
5985- std::string_view host_name{t_state.unmapped_url .host_get ()};
5986- swoc::bwprint (error_bw_buffer, " CONNECT : {::s} connecting to {} for host='{}' url='{}' fail_count='{}' marking down" ,
5987- swoc::bwf::Errno (t_state.current .server ->connect_result ), t_state.current .server ->dst_addr , host_name,
5988- swoc::bwf::FirstOf (url_str, " <none>" ), fail_count);
5989- Log::error (" %s" , error_bw_buffer.c_str ());
5990- SMDbg (dbg_ctl_http, " hostdb update marking IP: %s as down" , addrbuf);
5991- ATS_PROBE2 (hostdb_mark_ip_as_down, sm_id, addrbuf);
5992- } else {
5993- ATS_PROBE3 (hostdb_inc_ip_failcount, sm_id, addrbuf, fail_count);
5994- SMDbg (dbg_ctl_http, " hostdb increment IP failcount %s to %d" , addrbuf, fail_count);
5995- }
5996- } else { // Clear the failure
5997- info->active ->mark_up ();
5998- }
5973+ if (info->active == nullptr ) {
5974+ return ;
5975+ }
5976+
5977+ char addrbuf[INET6_ADDRPORTSTRLEN];
5978+ ats_ip_nptop (&t_state.current .server ->dst_addr .sa , addrbuf, sizeof (addrbuf));
5979+
5980+ uint8_t max_connect_retries = HttpTransact::origin_server_connect_attempts_max_retries (&t_state);
5981+ ts_seconds fail_window = t_state.txn_conf ->down_server_timeout ;
5982+
5983+ // Mark the host DOWN only after every attempt has failed. `max_connect_retries` counts only "retries", so the total attempt
5984+ // budget is `max_connect_retries + 1` (the initial connect plus each retry).
5985+ auto [down, fail_count] = info->active ->increment_fail_count (time_down, max_connect_retries + 1 , fail_window);
5986+
5987+ if (down) {
5988+ char *url_str = t_state.hdr_info .client_request .url_string_get_ref (nullptr );
5989+ std::string_view host_name{t_state.unmapped_url .host_get ()};
5990+ swoc::bwprint (error_bw_buffer, " CONNECT : {::s} connecting to {} for host='{}' url='{}' fail_count='{}' marking down" ,
5991+ swoc::bwf::Errno (t_state.current .server ->connect_result ), t_state.current .server ->dst_addr , host_name,
5992+ swoc::bwf::FirstOf (url_str, " <none>" ), fail_count);
5993+ Log::error (" %s" , error_bw_buffer.c_str ());
5994+ SMDbg (dbg_ctl_http, " hostdb update marking IP: %s as down" , addrbuf);
5995+ ATS_PROBE2 (hostdb_mark_ip_as_down, sm_id, addrbuf);
5996+ } else {
5997+ ATS_PROBE3 (hostdb_inc_ip_failcount, sm_id, addrbuf, fail_count);
5998+ SMDbg (dbg_ctl_http, " hostdb increment IP failcount %s to %d" , addrbuf, fail_count);
59995999 }
6000- #ifdef DEBUG
6001- ink_assert (std::chrono::system_clock::now () + t_state.txn_conf ->down_server_timeout > time_down);
6002- #endif
60036000}
60046001
60056002void
0 commit comments