diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index f8300b37e..15fbd80ae 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -771,30 +771,33 @@ void RsGxsDataAccess::processRequests() clearRequest(*cit); } + // We hve to make a copy of the mRequest list because it can be modified while we treat the requests. + // This may happen because the mutex cannot be added around the full loop since it takes too much time. + + std::map request_list_copy; + + { + RS_STACK_MUTEX(mDataMutex); + request_list_copy = mRequests; + } // process requests while (true) { GxsRequest* req = NULL; { - RsStackMutex stack(mDataMutex); /******* LOCKED *******/ - // get the first pending request - for (it = mRequests.begin(); it != mRequests.end(); ++it) - { - GxsRequest* reqCheck = it->second; - if (reqCheck->status == PENDING) + for (auto it:request_list_copy) + if (it.second->status == PENDING) { - req = reqCheck; + req = it.second; req->status = PARTIAL; break; } - } - } // END OF MUTEX. - - if (!req) { - break; } + if (!req) + break; + GroupMetaReq* gmr; GroupDataReq* gdr; GroupIdReq* gir;