You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2018/05/24 21:46:13 UTC

[trafficserver] branch master updated: Fix dicarding active lock in CPPAPI Async Timer.

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

amc 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 de8a4ad  Fix dicarding active lock in CPPAPI Async Timer.
de8a4ad is described below

commit de8a4ad76f090d0d44c1b6648337b3f30731bb7b
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Thu May 24 14:25:36 2018 -0500

    Fix dicarding active lock in CPPAPI Async Timer.
---
 lib/cppapi/AsyncTimer.cc | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/lib/cppapi/AsyncTimer.cc b/lib/cppapi/AsyncTimer.cc
index 556d032..cc44699 100644
--- a/lib/cppapi/AsyncTimer.cc
+++ b/lib/cppapi/AsyncTimer.cc
@@ -93,11 +93,17 @@ AsyncTimer::run()
 void
 AsyncTimer::cancel()
 {
-  if (!state_->cont_) {
+  // Assume this object is locked and the state isn't being updated elsewhere.
+  // Note that is not the same as the contained continuation being locked.
+  TSCont contp{state_->cont_}; // save this
+  if (!contp) {
     LOG_DEBUG("Already canceled");
     return;
   }
-  TSMutexLock(TSContMutexGet(state_->cont_)); // mutex will be unlocked in destroy
+
+  auto mutex{TSContMutexGet(contp)};
+  TSMutexLock(mutex); // prevent event dispatch for the continuation during this cancel.
+
   if (state_->initial_timer_action_) {
     LOG_DEBUG("Canceling initial timer action");
     TSActionCancel(state_->initial_timer_action_);
@@ -106,9 +112,12 @@ AsyncTimer::cancel()
     LOG_DEBUG("Canceling periodic timer action");
     TSActionCancel(state_->periodic_timer_action_);
   }
-  LOG_DEBUG("Destroying cont");
-  TSContDestroy(state_->cont_);
   state_->cont_ = nullptr;
+
+  TSMutexUnlock(mutex);
+
+  LOG_DEBUG("Destroying cont");
+  TSContDestroy(contp);
 }
 
 AsyncTimer::~AsyncTimer()

-- 
To stop receiving notification emails like this one, please contact
amc@apache.org.