gitbutlerapp/gitbutler · error

Project at ' ' is already being refreshed in the background…

Error message

Project at '{}' is already being refreshed in the background by another GitButler instance

What it means

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.

Solutions

  1. Close the other GitButler instance holding the lock, then retry
  2. Remove the stale lock file in the project data directory if no other instance is actually running (check for live processes first)
  3. Retry the operation after the other process exits; treat this error as retryable with backoff

Example fix

// before
let lock = try_exclusive_inter_process_access(&project_data, scope)?;
// after
let lock = match try_exclusive_inter_process_access(&project_data, scope) {
    Ok(l) => l,
    Err(e) if e.to_string().contains("already being refreshed") => {
        std::thread::sleep(Duration::from_millis(500));
        try_exclusive_inter_process_access(&project_data, scope)?
    }
    Err(e) => return Err(e),
};
Defensive patterns

Strategy: retry

Validate before calling

// check whether another live process holds the lock before attempting
if lock_file_exists(&project_data) && !other_instance_running() {
    std::fs::remove_file(lock_path(&project_data))?; // clear stale lock
}

Try / catch

match try_exclusive_inter_process_access(&project_data, scope) {
    Ok(lock) => lock,
    Err(e) if e.to_string().contains("already being refreshed") =>
        return Err(anyhow!("project busy; retry later")),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/2411cc81db9d0a71. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-core/src/sync.rs:68

    let got_lock = lock
        .try_lock()
        .context("Failed to check if lock is taken")?;
    if !got_lock {
        let error_message = match scope {
            LockScope::AllOperations => {
                format!(
                    "Project at '{}' is already opened for writing by another GitButler instance",
                    project_data.display()
                )
            }
            LockScope::BackgroundRefreshOperations => {
                format!(
                    "Project at '{}' is already being refreshed in the background by another GitButler instance",
                    project_data.display()
                )
            }
        };
        bail!(error_message);
    }
    Ok(lock)
}

/// Return a guard for exclusive (read+write) *in-process* repository access for the project at
/// `git_dir`, blocking while waiting for someone else in this process to release it, or for all
/// readers to disappear. Locking is fair.
/// Also use `project_data_dir` if `Some` to create an *inter-process* exclusive lock.
/// Creating, opening, or locking that file is best-effort. Failures are logged and ignored, so
/// the hard guarantee provided by this function remains in-process exclusivity only.
///
/// If the current process inherits Git's commit-hook environment (`GIT_EDITOR=:` together with
/// `GIT_INDEX_FILE`), acquiring the inter-process lock becomes non-blocking: if another process
/// already holds it, we continue without that file lock instead of waiting. This avoids
/// deadlocking hook re-entry when the parent GitButler command is already holding the same
/// inter-process lock while waiting for the hook to finish.
/// If `project_data_dir` is `None`, no inter-process lock is obtained.
///

View on GitHub (pinned to 58e5313667)