diff --git a/src/Cache.cpp b/src/Cache.cpp
index 452567c302ae7a1bba3cbf4ce879be798328869b..a1242633c16f6a29d0f2bb8ea67061ffd8f2c236 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -878,9 +878,9 @@ Cache::saveState(const mtx::responses::Sync &res)
         txn.commit();
 
         for (const auto &room : res.rooms.join) {
-                auto txn = lmdb::txn::begin(env_);
-                notifyForReadReceipts(txn, room.first);
-                txn.commit();
+                auto tmpTxn = lmdb::txn::begin(env_);
+                notifyForReadReceipts(tmpTxn, room.first);
+                tmpTxn.commit();
         }
 }