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 3e039a2  Reactivate active timeout enforcement
3e039a2 is described below

commit 3e039a28c9b68517c303a142c42fad6ff5f2b217
Author: Susan Hinrichs <shinr...@oath.com>
AuthorDate: Tue Aug 13 19:30:14 2019 +0000

    Reactivate active timeout enforcement
---
 iocore/net/P_UnixNetVConnection.h                 |  2 +-
 iocore/net/UnixNet.cc                             | 16 ++++--
 iocore/net/UnixNetVConnection.cc                  | 18 +++----
 tests/gold_tests/timeout/active_timeout.test.py   | 63 +++++++++++++++++++++++
 tests/gold_tests/timeout/inactive_timeout.test.py | 63 +++++++++++++++++++++++
 5 files changed, 149 insertions(+), 13 deletions(-)

diff --git a/iocore/net/P_UnixNetVConnection.h 
b/iocore/net/P_UnixNetVConnection.h
index 7b96144..128f572 100644
--- a/iocore/net/P_UnixNetVConnection.h
+++ b/iocore/net/P_UnixNetVConnection.h
@@ -379,7 +379,7 @@ UnixNetVConnection::set_active_timeout(ink_hrtime 
timeout_in)
 {
   Debug("socket", "Set active timeout=%" PRId64 ", NetVC=%p", timeout_in, 
this);
   active_timeout_in        = timeout_in;
-  next_activity_timeout_at = Thread::get_hrtime() + timeout_in;
+  next_activity_timeout_at = (active_timeout_in > 0) ? Thread::get_hrtime() + 
timeout_in : 0;
 }
 
 inline void
diff --git a/iocore/net/UnixNet.cc b/iocore/net/UnixNet.cc
index 8d387fa..248c93a 100644
--- a/iocore/net/UnixNet.cc
+++ b/iocore/net/UnixNet.cc
@@ -78,7 +78,11 @@ public:
         }
         Debug("inactivity_cop_verbose", "vc: %p now: %" PRId64 " timeout at: 
%" PRId64 " timeout in: %" PRId64, vc,
               ink_hrtime_to_sec(now), vc->next_inactivity_timeout_at, 
vc->inactivity_timeout_in);
-        vc->handleEvent(EVENT_IMMEDIATE, e);
+        vc->handleEvent(VC_EVENT_INACTIVITY_TIMEOUT, e);
+      } else if (vc->next_activity_timeout_at && vc->next_activity_timeout_at 
< now) {
+        Debug("inactivity_cop_verbose", "active vc: %p now: %" PRId64 " 
timeout at: %" PRId64 " timeout in: %" PRId64, vc,
+              ink_hrtime_to_sec(now), vc->next_activity_timeout_at, 
vc->active_timeout_in);
+        vc->handleEvent(VC_EVENT_ACTIVE_TIMEOUT, e);
       }
     }
     // The cop_list is empty now.
@@ -664,8 +668,14 @@ NetHandler::_close_vc(UnixNetVConnection *vc, ink_hrtime 
now, int &handle_event,
     // create a dummy event
     Event event;
     event.ethread = this_ethread();
-    if (vc->handleEvent(EVENT_IMMEDIATE, &event) == EVENT_DONE) {
-      ++handle_event;
+    if (vc->inactivity_timeout_in && vc->next_inactivity_timeout_at <= now) {
+      if (vc->handleEvent(VC_EVENT_INACTIVITY_TIMEOUT, &event) == EVENT_DONE) {
+        ++handle_event;
+      }
+    } else if (vc->active_timeout_in && vc->next_activity_timeout_at <= now) {
+      if (vc->handleEvent(VC_EVENT_ACTIVE_TIMEOUT, &event) == EVENT_DONE) {
+        ++handle_event;
+      }
     }
   }
 }
diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
index e47fb44..b35f115 100644
--- a/iocore/net/UnixNetVConnection.cc
+++ b/iocore/net/UnixNetVConnection.cc
@@ -1096,7 +1096,7 @@ UnixNetVConnection::acceptEvent(int event, Event *e)
 int
 UnixNetVConnection::mainEvent(int event, Event *e)
 {
-  ink_assert(event == EVENT_IMMEDIATE || event == EVENT_INTERVAL);
+  ink_assert(event == VC_EVENT_ACTIVE_TIMEOUT || event == 
VC_EVENT_INACTIVITY_TIMEOUT);
   ink_assert(thread == this_ethread());
 
   MUTEX_TRY_LOCK(hlock, get_NetHandler(thread)->mutex, e->ethread);
@@ -1120,18 +1120,18 @@ UnixNetVConnection::mainEvent(int event, Event *e)
   Event *t                      = nullptr;
   Event **signal_timeout        = &t;
 
-  if (event == EVENT_IMMEDIATE) {
-    /* BZ 49408 */
-    // ink_assert(inactivity_timeout_in);
-    // ink_assert(next_inactivity_timeout_at < Thread::get_hrtime());
-    if (!inactivity_timeout_in || next_inactivity_timeout_at > 
Thread::get_hrtime()) {
-      return EVENT_CONT;
-    }
+  switch (event) {
+  case VC_EVENT_INACTIVITY_TIMEOUT:
     signal_event      = VC_EVENT_INACTIVITY_TIMEOUT;
     signal_timeout_at = &next_inactivity_timeout_at;
-  } else {
+    break;
+  case VC_EVENT_ACTIVE_TIMEOUT:
     signal_event      = VC_EVENT_ACTIVE_TIMEOUT;
     signal_timeout_at = &next_activity_timeout_at;
+    break;
+  default:
+    ink_release_assert(!"BUG: unexpected event in 
UnixNetVConnection::mainEvent");
+    break;
   }
 
   *signal_timeout    = nullptr;
diff --git a/tests/gold_tests/timeout/active_timeout.test.py 
b/tests/gold_tests/timeout/active_timeout.test.py
new file mode 100644
index 0000000..ef2c25f
--- /dev/null
+++ b/tests/gold_tests/timeout/active_timeout.test.py
@@ -0,0 +1,63 @@
+'''
+'''
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+Test.Summary = 'Testing ATS active timeout'
+
+# need Curl
+Test.SkipUnless(
+    Condition.HasCurlFeature('http2')
+)
+
+ts = Test.MakeATSProcess("ts", select_ports=True, enable_tls=True)
+server = Test.MakeOriginServer("server", delay=8)
+
+request_header = {"headers": "GET /file HTTP/1.1\r\nHost: *\r\n\r\n", 
"timestamp": "5678", "body": ""}
+response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", 
"timestamp": "5678", "body": ""}
+
+server.addResponse("sessionfile.log", request_header, response_header)
+
+ts.addSSLfile("../tls/ssl/server.pem")
+ts.addSSLfile("../tls/ssl/server.key")
+
+ts.Disk.records_config.update({
+    'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
+    'proxy.config.ssl.server.private_key.path': 
'{0}'.format(ts.Variables.SSLDir),
+    'proxy.config.url_remap.remap_required': 1,
+    'proxy.config.http.transaction_active_timeout_out': 2,
+})
+
+ts.Disk.remap_config.AddLine(
+    'map / http://127.0.0.1:{0}/'.format(server.Variables.Port))
+
+ts.Disk.ssl_multicert_config.AddLine(
+    'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key'
+)
+
+tr = Test.AddTestRun("tr")
+tr.Processes.Default.StartBefore(server)
+tr.Processes.Default.StartBefore(ts, ready=When.PortOpen(ts.Variables.port))
+tr.Processes.Default.Command = 'curl -i  
http://127.0.0.1:{0}/file'.format(ts.Variables.port)
+tr.Processes.Default.Streams.stdout = Testers.ContainsExpression("Activity 
Timeout", "Request should fail with active timeout")
+
+tr2= Test.AddTestRun("tr")
+tr2.Processes.Default.Command = 'curl -k -i --http1.1 
https://127.0.0.1:{0}/file'.format(ts.Variables.ssl_port)
+tr2.Processes.Default.Streams.stdout = Testers.ContainsExpression("Activity 
Timeout", "Request should fail with active timeout")
+
+tr3= Test.AddTestRun("tr")
+tr3.Processes.Default.Command = 'curl -k -i --http2 
https://127.0.0.1:{0}/file'.format(ts.Variables.ssl_port)
+tr3.Processes.Default.Streams.stdout = Testers.ContainsExpression("Activity 
Timeout", "Request should fail with active timeout")
diff --git a/tests/gold_tests/timeout/inactive_timeout.test.py 
b/tests/gold_tests/timeout/inactive_timeout.test.py
new file mode 100644
index 0000000..3076274
--- /dev/null
+++ b/tests/gold_tests/timeout/inactive_timeout.test.py
@@ -0,0 +1,63 @@
+'''
+'''
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+Test.Summary = 'Testing ATS inactivity timeout'
+
+# need Curl
+Test.SkipUnless(
+    Condition.HasCurlFeature('http2')
+)
+
+ts = Test.MakeATSProcess("ts", select_ports=True, enable_tls=True)
+server = Test.MakeOriginServer("server", delay=8)
+
+request_header = {"headers": "GET /file HTTP/1.1\r\nHost: *\r\n\r\n", 
"timestamp": "5678", "body": ""}
+response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", 
"timestamp": "5678", "body": ""}
+
+server.addResponse("sessionfile.log", request_header, response_header)
+
+ts.addSSLfile("../tls/ssl/server.pem")
+ts.addSSLfile("../tls/ssl/server.key")
+
+ts.Disk.records_config.update({
+    'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
+    'proxy.config.ssl.server.private_key.path': 
'{0}'.format(ts.Variables.SSLDir),
+    'proxy.config.url_remap.remap_required': 1,
+    'proxy.config.http.transaction_no_activity_timeout_out': 2,
+})
+
+ts.Disk.remap_config.AddLine(
+    'map / http://127.0.0.1:{0}/'.format(server.Variables.Port))
+
+ts.Disk.ssl_multicert_config.AddLine(
+    'dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key'
+)
+
+tr = Test.AddTestRun("tr")
+tr.Processes.Default.StartBefore(server)
+tr.Processes.Default.StartBefore(ts, ready=When.PortOpen(ts.Variables.port))
+tr.Processes.Default.Command = 'curl -i  
http://127.0.0.1:{0}/file'.format(ts.Variables.port)
+tr.Processes.Default.Streams.stdout = Testers.ContainsExpression("Inactivity 
Timeout", "Request should fail with inactivity timeout")
+
+tr2= Test.AddTestRun("tr")
+tr2.Processes.Default.Command = 'curl -k -i --http1.1 
https://127.0.0.1:{0}/file'.format(ts.Variables.ssl_port)
+tr2.Processes.Default.Streams.stdout = Testers.ContainsExpression("Inactivity 
Timeout", "Request should fail with inactivity timeout")
+
+tr3= Test.AddTestRun("tr")
+tr3.Processes.Default.Command = 'curl -k -i --http2 
https://127.0.0.1:{0}/file'.format(ts.Variables.ssl_port)
+tr3.Processes.Default.Streams.stdout = Testers.ContainsExpression("Inactivity 
Timeout", "Request should fail with inactivity timeout")

Reply via email to