Browse Source

修复EndpointManager updateOutter并发导致的crash

wuxf 2 years ago
parent
commit
e87131bba2
2 changed files with 3 additions and 0 deletions
  1. 2 0
      servant/libservant/EndpointManager.cpp
  2. 1 0
      servant/servant/EndpointManager.h

+ 2 - 0
servant/libservant/EndpointManager.cpp

@@ -681,6 +681,7 @@ void EndpointManager::onUpdateOutter()
 //	LOG_CONSOLE_DEBUG << this->_objectProxy << ", valid:" << _valid << ", " << _outterUpdate.get() << endl;
 	assert(this->_objectProxy->getCommunicatorEpoll()->getThreadId() == this_thread::get_id());
 
+    lock_guard<mutex> l(_outterLocker);
     if(_outterUpdate)
     {
 		shared_ptr<OutterUpdate> outterUpdate = _outterUpdate;
@@ -704,6 +705,7 @@ void EndpointManager::updateEndpointsOutter(const set<EndpointInfo> & active, co
     //更新时间
 	_refreshTime = TNOWMS + _refreshInterval;
 
+    lock_guard<mutex> l(_outterLocker);
 	_outterUpdate = outterUpdate;
 }
 

+ 1 - 0
servant/servant/EndpointManager.h

@@ -562,6 +562,7 @@ private:
         set<EndpointInfo> inactive;
     };
 
+    mutex _outterLocker;
     shared_ptr<OutterUpdate>    _outterUpdate;
 
 };