You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2018/08/29 05:51:34 UTC

[trafficserver] 04/04: Acquire mutex lock before handleEvent() call

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

masaori pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 2621a0716f0e76f3a403383a87a154132960ac4e
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Wed Aug 29 14:51:04 2018 +0900

    Acquire mutex lock before handleEvent() call
---
 iocore/net/QUICNet.cc            | 3 +++
 iocore/net/QUICNetProcessor.cc   | 2 ++
 iocore/net/QUICNetVConnection.cc | 6 +++++-
 proxy/hq/QUICSimpleApp.cc        | 2 ++
 4 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/iocore/net/QUICNet.cc b/iocore/net/QUICNet.cc
index 8568280..9a4b649 100644
--- a/iocore/net/QUICNet.cc
+++ b/iocore/net/QUICNet.cc
@@ -69,14 +69,17 @@ QUICPollCont::_process_long_header_packet(QUICPollEvent *e, NetHandler *nh)
 
   QUICPacketType ptype = static_cast<QUICPacketType>(buf[0] & 0x7f);
   if (ptype == QUICPacketType::INITIAL && !vc->read.triggered) {
+    SCOPED_MUTEX_LOCK(lock, vc->mutex, this_ethread());
     vc->read.triggered = 1;
     vc->handle_received_packet(p);
     vc->handleEvent(QUIC_EVENT_PACKET_READ_READY, nullptr);
     e->free();
+
     return;
   }
 
   if (vc) {
+    SCOPED_MUTEX_LOCK(lock, vc->mutex, this_ethread());
     vc->read.triggered = 1;
     vc->handle_received_packet(p);
   } else {
diff --git a/iocore/net/QUICNetProcessor.cc b/iocore/net/QUICNetProcessor.cc
index 8807a15..e4c4ab1 100644
--- a/iocore/net/QUICNetProcessor.cc
+++ b/iocore/net/QUICNetProcessor.cc
@@ -192,6 +192,7 @@ QUICNetProcessor::main_accept(Continuation *cont, SOCKET fd, AcceptOptions const
   // char thr_name[MAX_THREAD_NAME_LENGTH];
 
   NetAccept *na = createNetAccept(opt);
+
   if (accept_threads < 0) {
     REC_ReadConfigInteger(accept_threads, "proxy.config.accept_threads");
   }
@@ -216,6 +217,7 @@ QUICNetProcessor::main_accept(Continuation *cont, SOCKET fd, AcceptOptions const
   na->action_->server = &na->server;
   na->init_accept();
 
+  SCOPED_MUTEX_LOCK(lock, na->mutex, this_ethread());
   udpNet.UDPBind((Continuation *)na, &na->server.accept_addr.sa, 1048576, 1048576);
 
   return na->action_.get();
diff --git a/iocore/net/QUICNetVConnection.cc b/iocore/net/QUICNetVConnection.cc
index c7a41fc..7b79c48 100644
--- a/iocore/net/QUICNetVConnection.cc
+++ b/iocore/net/QUICNetVConnection.cc
@@ -720,7 +720,9 @@ QUICNetVConnection::state_connection_closed(int event, Event *data)
     // TODO: Drop record from Connection-ID - QUICNetVConnection table in QUICPacketHandler
     // Shutdown loss detector
     for (auto s : QUIC_PN_SPACES) {
-      this->_loss_detector[static_cast<int>(s)]->handleEvent(QUIC_EVENT_LD_SHUTDOWN, nullptr);
+      QUICLossDetector *ld = this->_loss_detector[static_cast<int>(s)];
+      SCOPED_MUTEX_LOCK(lock, ld->mutex, this_ethread());
+      ld->handleEvent(QUIC_EVENT_LD_SHUTDOWN, nullptr);
     }
 
     if (this->nh) {
@@ -750,7 +752,9 @@ QUICNetVConnection::get_udp_con()
 void
 QUICNetVConnection::net_read_io(NetHandler *nh, EThread *lthread)
 {
+  SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread());
   this->handleEvent(QUIC_EVENT_PACKET_READ_READY, nullptr);
+
   return;
 }
 
diff --git a/proxy/hq/QUICSimpleApp.cc b/proxy/hq/QUICSimpleApp.cc
index 6d77af7..fb42b25 100644
--- a/proxy/hq/QUICSimpleApp.cc
+++ b/proxy/hq/QUICSimpleApp.cc
@@ -75,6 +75,7 @@ QUICSimpleApp::main_event_handler(int event, Event *data)
 
         txn->new_transaction();
       } else {
+        SCOPED_MUTEX_LOCK(lock, txn->mutex, this_ethread());
         txn->handleEvent(event);
       }
     }
@@ -82,6 +83,7 @@ QUICSimpleApp::main_event_handler(int event, Event *data)
   case VC_EVENT_WRITE_READY:
   case VC_EVENT_WRITE_COMPLETE:
     if (txn != nullptr) {
+      SCOPED_MUTEX_LOCK(lock, txn->mutex, this_ethread());
       txn->handleEvent(event);
     }
     break;