{"record":{"id":"2411cc81db9d0a71","repo":"gitbutlerapp/gitbutler","slug":"project-at-is-already-being-refreshed-in-the","errorCode":null,"errorMessage":"Project at '{}' is already being refreshed in the background by another GitButler instance","messagePattern":"Project at '(.+?)' is already being refreshed in the background by another GitButler instance","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-core/src/sync.rs","lineNumber":68,"sourceCode":"    let got_lock = lock\n        .try_lock()\n        .context(\"Failed to check if lock is taken\")?;\n    if !got_lock {\n        let error_message = match scope {\n            LockScope::AllOperations => {\n                format!(\n                    \"Project at '{}' is already opened for writing by another GitButler instance\",\n                    project_data.display()\n                )\n            }\n            LockScope::BackgroundRefreshOperations => {\n                format!(\n                    \"Project at '{}' is already being refreshed in the background by another GitButler instance\",\n                    project_data.display()\n                )\n            }\n        };\n        bail!(error_message);\n    }\n    Ok(lock)\n}\n\n/// Return a guard for exclusive (read+write) *in-process* repository access for the project at\n/// `git_dir`, blocking while waiting for someone else in this process to release it, or for all\n/// readers to disappear. Locking is fair.\n/// Also use `project_data_dir` if `Some` to create an *inter-process* exclusive lock.\n/// Creating, opening, or locking that file is best-effort. Failures are logged and ignored, so\n/// the hard guarantee provided by this function remains in-process exclusivity only.\n///\n/// If the current process inherits Git's commit-hook environment (`GIT_EDITOR=:` together with\n/// `GIT_INDEX_FILE`), acquiring the inter-process lock becomes non-blocking: if another process\n/// already holds it, we continue without that file lock instead of waiting. This avoids\n/// deadlocking hook re-entry when the parent GitButler command is already holding the same\n/// inter-process lock while waiting for the hook to finish.\n/// If `project_data_dir` is `None`, no inter-process lock is obtained.\n///","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-core/src/sync.rs#L50-L86","documentation":"try_exclusive_inter_process_access takes an OS-level lock file to prevent two GitButler processes from refreshing the same project concurrently. If another instance holds the background-refresh lock, it bails with this message naming the project data directory.","triggerScenarios":"Opening or starting a background refresh for a project while another GitButler process still holds the refresh lock file for that project data directory (no blocking — it fails immediately).","commonSituations":"Two GitButler instances (or a GUI plus CLI) open simultaneously on the same project; a stale lock file left behind by a crashed process; the lock-holding process is slow to exit.","solutions":["Close the other GitButler instance holding the lock, then retry","Remove the stale lock file in the project data directory if no other instance is actually running (check for live processes first)","Retry the operation after the other process exits; treat this error as retryable with backoff"],"exampleFix":"// before\nlet lock = try_exclusive_inter_process_access(&project_data, scope)?;\n// after\nlet lock = match try_exclusive_inter_process_access(&project_data, scope) {\n    Ok(l) => l,\n    Err(e) if e.to_string().contains(\"already being refreshed\") => {\n        std::thread::sleep(Duration::from_millis(500));\n        try_exclusive_inter_process_access(&project_data, scope)?\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":"// check whether another live process holds the lock before attempting\nif lock_file_exists(&project_data) && !other_instance_running() {\n    std::fs::remove_file(lock_path(&project_data))?; // clear stale lock\n}","typeGuard":null,"tryCatchPattern":"match try_exclusive_inter_process_access(&project_data, scope) {\n    Ok(lock) => lock,\n    Err(e) if e.to_string().contains(\"already being refreshed\") =>\n        return Err(anyhow!(\"project busy; retry later\")),\n    Err(e) => return Err(e),\n}","preventionTips":["Run only one GitButler instance per project data directory","Detect and clean stale lock files after crashes","Use exponential backoff on this error; it may clear once the other process exits"],"tags":["rust","locking","concurrency","ipc"],"backgroundTag":"resource-already-locked","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}