You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by sh...@apache.org on 2019/09/03 14:02:02 UTC

[trafficserver] branch master updated: Add helper functions to apply api timeouts consistently.

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

shinrich 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 a1e6f5e  Add helper functions to apply api timeouts consistently.
a1e6f5e is described below

commit a1e6f5ea5d6638ff59fd3b716b012b980bebf9d7
Author: Susan Hinrichs <sh...@oath.com>
AuthorDate: Mon Aug 12 15:24:30 2019 +0000

    Add helper functions to apply api timeouts consistently.
---
 proxy/http/HttpSM.cc | 91 ++++++++++++++++++++++++++++++++--------------------
 proxy/http/HttpSM.h  |  4 +++
 2 files changed, 60 insertions(+), 35 deletions(-)

diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 9d586ee..a7c9a3d 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -281,6 +281,54 @@ HttpVCTable::cleanup_all()
     default_handler = _h;                 \
   }
 
+/*
+ * Helper functions to ensure that the parallel
+ * API set timeouts are set consistenly with the records.config settings
+ */
+void
+HttpSM::set_server_netvc_inactivity_timeout(NetVConnection *netvc)
+{
+  if (netvc) {
+    if (t_state.api_txn_no_activity_timeout_value != -1) {
+      netvc->set_inactivity_timeout(HRTIME_MSECONDS(t_state.api_txn_no_activity_timeout_value));
+    } else {
+      netvc->set_inactivity_timeout(HRTIME_SECONDS(t_state.txn_conf->transaction_no_activity_timeout_out));
+    }
+  }
+}
+
+void
+HttpSM::set_server_netvc_active_timeout(NetVConnection *netvc)
+{
+  if (netvc) {
+    if (t_state.api_txn_active_timeout_value != -1) {
+      netvc->set_active_timeout(HRTIME_MSECONDS(t_state.api_txn_active_timeout_value));
+    } else {
+      netvc->set_active_timeout(HRTIME_SECONDS(t_state.txn_conf->transaction_active_timeout_out));
+    }
+  }
+}
+
+void
+HttpSM::set_server_netvc_connect_timeout(NetVConnection *netvc)
+{
+  if (netvc) {
+    if (t_state.api_txn_connect_timeout_value != -1) {
+      netvc->set_inactivity_timeout(HRTIME_MSECONDS(t_state.api_txn_connect_timeout_value));
+    } else {
+      int connect_timeout;
+      if (t_state.method == HTTP_WKSIDX_POST || t_state.method == HTTP_WKSIDX_PUT) {
+        connect_timeout = t_state.txn_conf->post_connect_attempts_timeout;
+      } else if (t_state.current.server == &t_state.parent_info) {
+        connect_timeout = t_state.txn_conf->parent_connect_timeout;
+      } else {
+        connect_timeout = t_state.txn_conf->connect_attempts_timeout;
+      }
+      netvc->set_inactivity_timeout(HRTIME_SECONDS(connect_timeout));
+    }
+  }
+}
+
 HttpSM::HttpSM() : Continuation(nullptr), vc_table(this) {}
 
 void
@@ -1114,8 +1162,8 @@ HttpSM::state_raw_http_server_open(int event, void *data)
     t_state.current.state    = HttpTransact::CONNECTION_ALIVE;
     ats_ip_copy(&t_state.server_info.src_addr, netvc->get_local_addr());
 
-    netvc->set_inactivity_timeout(HRTIME_SECONDS(t_state.txn_conf->transaction_no_activity_timeout_out));
-    netvc->set_active_timeout(HRTIME_SECONDS(t_state.txn_conf->transaction_active_timeout_out));
+    set_server_netvc_inactivity_timeout(netvc);
+    set_server_netvc_active_timeout(netvc);
     break;
 
   case VC_EVENT_ERROR:
@@ -1762,11 +1810,7 @@ HttpSM::state_http_server_open(int event, void *data)
     server_entry->vc_handler = &HttpSM::state_send_server_request_header;
 
     // Reset the timeout to the non-connect timeout
-    if (t_state.api_txn_no_activity_timeout_value != -1) {
-      server_session->get_netvc()->set_inactivity_timeout(HRTIME_MSECONDS(t_state.api_txn_no_activity_timeout_value));
-    } else {
-      server_session->get_netvc()->set_inactivity_timeout(HRTIME_SECONDS(t_state.txn_conf->transaction_no_activity_timeout_out));
-    }
+    set_server_netvc_inactivity_timeout(server_session->get_netvc());
     handle_http_server_open();
     return 0;
   case EVENT_INTERVAL: // Delayed call from another thread
@@ -1855,11 +1899,7 @@ HttpSM::state_read_server_response_header(int event, void *data)
   if (server_response_hdr_bytes == 0) {
     milestones[TS_MILESTONE_SERVER_FIRST_READ] = Thread::get_hrtime();
 
-    if (t_state.api_txn_no_activity_timeout_value != -1) {
-      server_session->get_netvc()->set_inactivity_timeout(HRTIME_MSECONDS(t_state.api_txn_no_activity_timeout_value));
-    } else {
-      server_session->get_netvc()->set_inactivity_timeout(HRTIME_SECONDS(t_state.txn_conf->transaction_no_activity_timeout_out));
-    }
+    set_server_netvc_inactivity_timeout(server_session->get_netvc());
 
     // For requests that contain a body, we can cancel the ua inactivity timeout.
     if (ua_txn && t_state.hdr_info.request_content_length) {
@@ -5678,7 +5718,7 @@ HttpSM::do_setup_post_tunnel(HttpVC_t to_vc_type)
   }
 
   ua_txn->set_inactivity_timeout(HRTIME_SECONDS(t_state.txn_conf->transaction_no_activity_timeout_in));
-  server_session->get_netvc()->set_inactivity_timeout(HRTIME_SECONDS(t_state.txn_conf->transaction_no_activity_timeout_out));
+  set_server_netvc_inactivity_timeout(server_session->get_netvc());
 
   tunnel.tunnel_run(p);
 
@@ -5909,27 +5949,8 @@ HttpSM::attach_server_session(Http1ServerSession *s)
   // Set the inactivity timeout to the connect timeout so that we
   //   we fail this server if it doesn't start sending the response
   //   header
-  MgmtInt connect_timeout;
-
-  if (t_state.method == HTTP_WKSIDX_POST || t_state.method == HTTP_WKSIDX_PUT) {
-    connect_timeout = t_state.txn_conf->post_connect_attempts_timeout;
-  } else if (t_state.current.server == &t_state.parent_info) {
-    connect_timeout = t_state.txn_conf->parent_connect_timeout;
-  } else {
-    connect_timeout = t_state.txn_conf->connect_attempts_timeout;
-  }
-
-  if (t_state.api_txn_connect_timeout_value != -1) {
-    server_session->get_netvc()->set_inactivity_timeout(HRTIME_MSECONDS(t_state.api_txn_connect_timeout_value));
-  } else {
-    server_session->get_netvc()->set_inactivity_timeout(HRTIME_SECONDS(connect_timeout));
-  }
-
-  if (t_state.api_txn_active_timeout_value != -1) {
-    server_session->get_netvc()->set_active_timeout(HRTIME_MSECONDS(t_state.api_txn_active_timeout_value));
-  } else {
-    server_session->get_netvc()->set_active_timeout(HRTIME_SECONDS(t_state.txn_conf->transaction_active_timeout_out));
-  }
+  set_server_netvc_connect_timeout(server_session->get_netvc());
+  set_server_netvc_active_timeout(server_session->get_netvc());
 
   if (plugin_tunnel_type != HTTP_NO_PLUGIN_TUNNEL || will_be_private_ss) {
     SMDebug("http_ss", "Setting server session to private");
@@ -5941,7 +5962,7 @@ void
 HttpSM::setup_server_send_request_api()
 {
   // Make sure the VC is on the correct timeout
-  server_session->get_netvc()->set_inactivity_timeout(HRTIME_SECONDS(t_state.txn_conf->transaction_no_activity_timeout_out));
+  set_server_netvc_inactivity_timeout(server_session->get_netvc());
   t_state.api_next_action = HttpTransact::SM_ACTION_API_SEND_REQUEST_HDR;
   do_api_callout();
 }
diff --git a/proxy/http/HttpSM.h b/proxy/http/HttpSM.h
index ab26c66..748d307 100644
--- a/proxy/http/HttpSM.h
+++ b/proxy/http/HttpSM.h
@@ -612,6 +612,10 @@ public:
     return _client_transaction_id;
   }
 
+  void set_server_netvc_inactivity_timeout(NetVConnection *netvc);
+  void set_server_netvc_active_timeout(NetVConnection *netvc);
+  void set_server_netvc_connect_timeout(NetVConnection *netvc);
+
 private:
   PostDataBuffers _postbuf;
   int _client_connection_id = -1, _client_transaction_id = -1;