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)) {
@@ -5973,34 +5969,35 @@ HttpSM::do_transform_open()
59735969void
59745970HttpSM::mark_host_failure (ResolveInfo *info, ts_time time_down)
59755971{
5976- char addrbuf[INET6_ADDRPORTSTRLEN] ;
5972+ ink_assert (time_down != TS_TIME_ZERO) ;
59775973
5978- if (info->active ) {
5979- if (time_down != TS_TIME_ZERO) {
5980- ats_ip_nptop (&t_state.current .server ->dst_addr .sa , addrbuf, sizeof (addrbuf));
5981- // Increment the fail_count
5982- if (auto [down, fail_count] = info->active ->increment_fail_count (time_down, t_state.txn_conf ->connect_attempts_rr_retries ,
5983- t_state.txn_conf ->down_server_timeout );
5984- down) {
5985- char *url_str = t_state.hdr_info .client_request .url_string_get_ref (nullptr );
5986- std::string_view host_name{t_state.unmapped_url .host_get ()};
5987- swoc::bwprint (error_bw_buffer, " CONNECT : {::s} connecting to {} for host='{}' url='{}' fail_count='{}' marking down" ,
5988- swoc::bwf::Errno (t_state.current .server ->connect_result ), t_state.current .server ->dst_addr , host_name,
5989- swoc::bwf::FirstOf (url_str, " <none>" ), fail_count);
5990- Log::error (" %s" , error_bw_buffer.c_str ());
5991- SMDbg (dbg_ctl_http, " hostdb update marking IP: %s as down" , addrbuf);
5992- ATS_PROBE2 (hostdb_mark_ip_as_down, sm_id, addrbuf);
5993- } else {
5994- ATS_PROBE3 (hostdb_inc_ip_failcount, sm_id, addrbuf, fail_count);
5995- SMDbg (dbg_ctl_http, " hostdb increment IP failcount %s to %d" , addrbuf, fail_count);
5996- }
5997- } else { // Clear the failure
5998- info->active ->mark_up ();
5999- }
5974+ if (info->active == nullptr ) {
5975+ return ;
5976+ }
5977+
5978+ char addrbuf[INET6_ADDRPORTSTRLEN];
5979+ ats_ip_nptop (&t_state.current .server ->dst_addr .sa , addrbuf, sizeof (addrbuf));
5980+
5981+ uint8_t max_connect_retries = HttpTransact::origin_server_connect_attempts_max_retries (&t_state);
5982+ ts_seconds fail_window = t_state.txn_conf ->down_server_timeout ;
5983+
5984+ // Mark the host DOWN only after every attempt has failed. `max_connect_retries` counts only "retries", so the total attempt
5985+ // budget is `max_connect_retries + 1` (the initial connect plus each retry).
5986+ auto [down, fail_count] = info->active ->increment_fail_count (time_down, max_connect_retries + 1 , fail_window);
5987+
5988+ if (down) {
5989+ char *url_str = t_state.hdr_info .client_request .url_string_get_ref (nullptr );
5990+ std::string_view host_name{t_state.unmapped_url .host_get ()};
5991+ swoc::bwprint (error_bw_buffer, " CONNECT : {::s} connecting to {} for host='{}' url='{}' fail_count='{}' marking down" ,
5992+ swoc::bwf::Errno (t_state.current .server ->connect_result ), t_state.current .server ->dst_addr , host_name,
5993+ swoc::bwf::FirstOf (url_str, " <none>" ), fail_count);
5994+ Log::error (" %s" , error_bw_buffer.c_str ());
5995+ SMDbg (dbg_ctl_http, " hostdb update marking IP: %s as down" , addrbuf);
5996+ ATS_PROBE2 (hostdb_mark_ip_as_down, sm_id, addrbuf);
5997+ } else {
5998+ ATS_PROBE3 (hostdb_inc_ip_failcount, sm_id, addrbuf, fail_count);
5999+ SMDbg (dbg_ctl_http, " hostdb increment IP failcount %s to %d" , addrbuf, fail_count);
60006000 }
6001- #ifdef DEBUG
6002- ink_assert (std::chrono::system_clock::now () + t_state.txn_conf ->down_server_timeout > time_down);
6003- #endif
60046001}
60056002
60066003void
0 commit comments