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 54b8caf  Fix TSHttpTxnReenable to schedule back to original SM thread
54b8caf is described below

commit 54b8caf6f5b1ddb7b6100d13af6377853bfac489
Author: Susan Hinrichs <[email protected]>
AuthorDate: Fri Sep 20 14:33:05 2019 +0000

    Fix TSHttpTxnReenable to schedule back to original SM thread
---
 proxy/http/HttpSM.cc         |  3 +++
 src/traffic_server/InkAPI.cc | 18 +++++++++---------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 3bec8b5..8b7044e 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -373,6 +373,9 @@ HttpSM::init()
 
   SET_HANDLER(&HttpSM::main_handler);
 
+  // Remember where this SM is running so it gets returned correctly
+  this->setThreadAffinity(this_ethread());
+
 #ifdef USE_HTTP_DEBUG_LISTS
   ink_mutex_acquire(&debug_sm_list_mutex);
   debug_sm_list.push(this);
diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc
index 32b595a..f6015e5 100644
--- a/src/traffic_server/InkAPI.cc
+++ b/src/traffic_server/InkAPI.cc
@@ -6087,20 +6087,20 @@ TSHttpTxnReenable(TSHttpTxn txnp, TSEvent event)
   // created using the ATS EThread API, eth will be NULL, and the
   // continuation needs to be called back on a REGULAR thread.
   //
-  // If this function is being executed on a thread created by the API
-  // which is DEDICATED, the continuation needs to be called back on a
-  // REGULAR thread.
-  if (eth == nullptr || eth->tt != REGULAR || !eth->is_event_type(ET_NET)) {
-    eventProcessor.schedule_imm(new TSHttpSMCallback(sm, event), ET_NET);
-  } else {
+  // If we are not coming from the thread associated with the state machine,
+  // reschedule.  Also reschedule if we cannot get the state machine lock.
+  if (eth != nullptr && sm->getThreadAffinity() == eth) {
     MUTEX_TRY_LOCK(trylock, sm->mutex, eth);
-    if (!trylock.is_locked()) {
-      eventProcessor.schedule_imm(new TSHttpSMCallback(sm, event), ET_NET);
-    } else {
+    if (trylock.is_locked()) {
       ink_assert(eth->is_event_type(ET_NET));
       sm->state_api_callback((int)event, nullptr);
+      return;
     }
   }
+  // Couldn't call the handler directly, schedule to the original SM thread
+  TSHttpSMCallback *cb = new TSHttpSMCallback(sm, event);
+  cb->setThreadAffinity(sm->getThreadAffinity());
+  eventProcessor.schedule_imm(cb, ET_NET);
 }
 
 TSReturnCode TSHttpArgIndexNameLookup(UserArg::Type type, const char *name, 
int *arg_idx, const char **description);

Reply via email to