mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-04 17:15:31 -05:00
fixed deadlock due to cross-locking RsGxsNetService and RsGxsGenExchange (reported by sss)
This commit is contained in:
parent
1ef11a27fd
commit
f8f040bde9
@ -397,21 +397,33 @@ void RsGxsNetService::processObserverNotifications()
|
|||||||
GXSNETDEBUG___ << "Processing observer notification." << std::endl;
|
GXSNETDEBUG___ << "Processing observer notification." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Observer notifycation should never be done explicitly within a Mutex-protected region, because of the risk
|
||||||
|
// of causing a cross-deadlock between the observer (RsGxsGenExchange) and the network layer (RsGxsNetService).
|
||||||
|
|
||||||
std::vector<RsNxsGrp*> grps_copy ;
|
std::vector<RsNxsGrp*> grps_copy ;
|
||||||
std::vector<RsNxsMsg*> msgs_copy ;
|
std::vector<RsNxsMsg*> msgs_copy ;
|
||||||
|
std::set<RsGxsGroupId> stat_copy ;
|
||||||
|
std::set<RsGxsGroupId> keys_copy ;
|
||||||
|
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mNxsMutex) ;
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
grps_copy = mNewGroupsToNotify ;
|
grps_copy = mNewGroupsToNotify ;
|
||||||
msgs_copy = mNewMessagesToNotify ;
|
msgs_copy = mNewMessagesToNotify ;
|
||||||
|
stat_copy = mNewStatsToNotify ;
|
||||||
|
keys_copy = mNewPublishKeysToNotify ;
|
||||||
|
|
||||||
mNewGroupsToNotify.clear() ;
|
mNewGroupsToNotify.clear() ;
|
||||||
mNewMessagesToNotify.clear() ;
|
mNewMessagesToNotify.clear() ;
|
||||||
|
mNewStatsToNotify.clear() ;
|
||||||
|
mNewPublishKeysToNotify.clear() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
mObserver->notifyNewGroups(grps_copy);
|
if(!grps_copy.empty()) mObserver->notifyNewGroups (grps_copy);
|
||||||
mObserver->notifyNewMessages(msgs_copy);
|
if(!msgs_copy.empty()) mObserver->notifyNewMessages(msgs_copy);
|
||||||
|
|
||||||
|
for(std::set<RsGxsGroupId>::const_iterator it(keys_copy.begin());it!=keys_copy.end();++it) mObserver->notifyReceivePublishKey(*it);
|
||||||
|
for(std::set<RsGxsGroupId>::const_iterator it(stat_copy.begin());it!=stat_copy.end();++it) mObserver->notifyChangedGroupStats(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsGxsNetService::rejectMessage(const RsGxsMessageId& msg_id)
|
void RsGxsNetService::rejectMessage(const RsGxsMessageId& msg_id)
|
||||||
@ -813,8 +825,6 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs)
|
|||||||
#ifdef NXS_NET_DEBUG_6
|
#ifdef NXS_NET_DEBUG_6
|
||||||
GXSNETDEBUG_PG(grs->PeerId(),grs->grpId) << "Received Grp update stats item from peer " << grs->PeerId() << " for group " << grs->grpId << ", reporting " << grs->number_of_posts << " posts." << std::endl;
|
GXSNETDEBUG_PG(grs->PeerId(),grs->grpId) << "Received Grp update stats item from peer " << grs->PeerId() << " for group " << grs->grpId << ", reporting " << grs->number_of_posts << " posts." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
bool should_notify = false ;
|
|
||||||
{
|
|
||||||
RS_STACK_MUTEX(mNxsMutex) ;
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
RsGxsGrpConfig& rec(mServerGrpConfigMap[grs->grpId]) ;
|
RsGxsGrpConfig& rec(mServerGrpConfigMap[grs->grpId]) ;
|
||||||
|
|
||||||
@ -826,10 +836,7 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs)
|
|||||||
rec.update_TS = time(NULL) ;
|
rec.update_TS = time(NULL) ;
|
||||||
|
|
||||||
if (old_count != rec.max_visible_count || old_suppliers_count != rec.suppliers.ids.size())
|
if (old_count != rec.max_visible_count || old_suppliers_count != rec.suppliers.ids.size())
|
||||||
should_notify = true ;
|
mNewStatsToNotify.insert(grs->grpId) ;
|
||||||
}
|
|
||||||
if(should_notify)
|
|
||||||
mObserver->notifyChangedGroupStats(grs->grpId);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cerr << "(EE) RsGxsNetService::handleRecvSyncGrpStatistics(): unknown item type " << grs->request_type << " found. This is a bug." << std::endl;
|
std::cerr << "(EE) RsGxsNetService::handleRecvSyncGrpStatistics(): unknown item type " << grs->request_type << " found. This is a bug." << std::endl;
|
||||||
@ -2701,7 +2708,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
|||||||
gnsr.max_visible_count = std::max(gnsr.max_visible_count, mcount) ;
|
gnsr.max_visible_count = std::max(gnsr.max_visible_count, mcount) ;
|
||||||
|
|
||||||
if (oldVisibleCount != gnsr.max_visible_count || oldSuppliersCount != gnsr.suppliers.ids.size())
|
if (oldVisibleCount != gnsr.max_visible_count || oldSuppliersCount != gnsr.suppliers.ids.size())
|
||||||
mObserver->notifyChangedGroupStats(grpId);
|
mNewStatsToNotify.insert(grpId) ;
|
||||||
|
|
||||||
#ifdef NXS_NET_DEBUG_1
|
#ifdef NXS_NET_DEBUG_1
|
||||||
GXSNETDEBUG_PG(item->PeerId(),grpId) << " grpId = " << grpId << std::endl;
|
GXSNETDEBUG_PG(item->PeerId(),grpId) << " grpId = " << grpId << std::endl;
|
||||||
@ -4776,7 +4783,7 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
|
|||||||
#ifdef NXS_NET_DEBUG
|
#ifdef NXS_NET_DEBUG
|
||||||
GXSNETDEBUG_PG(item->PeerId(),item->grpId)<< " updated database with new publish keys." << std::endl;
|
GXSNETDEBUG_PG(item->PeerId(),item->grpId)<< " updated database with new publish keys." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
mObserver->notifyReceivePublishKey(item->grpId);
|
mNewPublishKeysToNotify.insert(item->grpId) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -564,8 +564,11 @@ private:
|
|||||||
RsServiceInfo mServiceInfo;
|
RsServiceInfo mServiceInfo;
|
||||||
|
|
||||||
std::map<RsGxsMessageId,time_t> mRejectedMessages;
|
std::map<RsGxsMessageId,time_t> mRejectedMessages;
|
||||||
|
|
||||||
std::vector<RsNxsGrp*> mNewGroupsToNotify ;
|
std::vector<RsNxsGrp*> mNewGroupsToNotify ;
|
||||||
std::vector<RsNxsMsg*> mNewMessagesToNotify ;
|
std::vector<RsNxsMsg*> mNewMessagesToNotify ;
|
||||||
|
std::set<RsGxsGroupId> mNewStatsToNotify ;
|
||||||
|
std::set<RsGxsGroupId> mNewPublishKeysToNotify ;
|
||||||
|
|
||||||
void debugDump();
|
void debugDump();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user