From 50bbdc65c8adccaf2d34fd90ee9f3897c347c667 Mon Sep 17 00:00:00 2001 From: Ben Radford Date: Tue, 16 May 2023 13:53:31 +0100 Subject: [PATCH] Do not attempt to acquire big-lock when read-only. --- src/libstore/local-store.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index d219f3e95..94176c62f 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -271,10 +271,12 @@ LocalStore::LocalStore(const Params & params) /* Acquire the big fat lock in shared mode to make sure that no schema upgrade is in progress. */ - Path globalLockPath = dbDir + "/big-lock"; - globalLock = openLockFile(globalLockPath.c_str(), true); + if (!readOnly) { + Path globalLockPath = dbDir + "/big-lock"; + globalLock = openLockFile(globalLockPath.c_str(), true); + } - if (!lockFile(globalLock.get(), ltRead, false)) { + if (!readOnly && !lockFile(globalLock.get(), ltRead, false)) { printInfo("waiting for the big Nix store lock..."); lockFile(globalLock.get(), ltRead, true); } @@ -305,7 +307,7 @@ LocalStore::LocalStore(const Params & params) "which is no longer supported. To convert to the new format,\n" "please upgrade Nix to version 1.11 first."); - if (!lockFile(globalLock.get(), ltWrite, false)) { + if (!readOnly && !lockFile(globalLock.get(), ltWrite, false)) { printInfo("waiting for exclusive access to the Nix store..."); lockFile(globalLock.get(), ltNone, false); // We have acquired a shared lock; release it to prevent deadlocks lockFile(globalLock.get(), ltWrite, true); @@ -340,7 +342,8 @@ LocalStore::LocalStore(const Params & params) writeFile(schemaPath, fmt("%1%", nixSchemaVersion), 0666, true); - lockFile(globalLock.get(), ltRead, true); + if (!readOnly) + lockFile(globalLock.get(), ltRead, true); } else openDB(*state, false);