}
void RequestContext::clearContextData(const std::string& val) {
- data_.wlock()->erase(val);
+ std::unique_ptr<RequestData> requestData;
+ // Delete the RequestData after giving up the wlock just in case one of the
+ // RequestData destructors will try to grab the lock again.
+ {
+ auto wlock = data_.wlock();
+ auto it = wlock->find(val);
+ if (it != wlock->end()) {
+ requestData = std::move(it->second);
+ wlock->erase(it);
+ }
+ }
}
std::shared_ptr<RequestContext> RequestContext::setContext(