diff --git a/src/ripple/nodestore/impl/DatabaseRotatingImp.h b/src/ripple/nodestore/impl/DatabaseRotatingImp.h index b2807eeabc..3a9fd302b4 100644 --- a/src/ripple/nodestore/impl/DatabaseRotatingImp.h +++ b/src/ripple/nodestore/impl/DatabaseRotatingImp.h @@ -22,6 +22,8 @@ #include +#include + namespace ripple { namespace NodeStore { @@ -82,7 +84,13 @@ public: private: std::shared_ptr writableBackend_; std::shared_ptr archiveBackend_; - mutable std::mutex mutex_; + // This needs to be a recursive mutex because callbacks in `rotateWithLock` + // can call function that also lock the mutex. A current example of this is + // a callback from SHAMapStoreImp, which calls `clearCaches`. This + // `clearCaches` call eventually calls `fetchNodeObject` which tries to + // relock the mutex. It would be desirable to rewrite the code so the lock + // was not held during a callback. + mutable std::recursive_mutex mutex_; std::shared_ptr fetchNodeObject(