diff --git a/src/jamidht/conversation.cpp b/src/jamidht/conversation.cpp
index 22812c3effc39dbb5a36992ad577f3cc75cd9c65..31119c86f1e954ce6b5b1e2e0ec1336c6616d4ac 100644
--- a/src/jamidht/conversation.cpp
+++ b/src/jamidht/conversation.cpp
@@ -1603,10 +1603,13 @@ Conversation::lastCommitId() const
     options.nbOfCommits = 1;
     options.skipMerge = true;
     History optHistory;
-    std::lock_guard wlk(pimpl_->writeMtx_); // Avoid any write during a loading operation
-    std::lock_guard lk(pimpl_->historyMtx_);
-    if (!pimpl_->loadedHistory_.messageList.empty())
-        return (*pimpl_->loadedHistory_.messageList.begin())->id;
+    {
+        std::lock_guard lk(pimpl_->historyMtx_);
+        if (!pimpl_->loadedHistory_.messageList.empty())
+            return (*pimpl_->loadedHistory_.messageList.begin())->id;
+    }
+
+    std::lock_guard lk(pimpl_->writeMtx_);
     auto res = pimpl_->loadMessages2(options, &optHistory);
     if (res.empty())
         return {};