Skip to content

Frequent errors: Could not acquire lock for index file ... The lockfile at '.git/index.lock' might need manual deletion #7530

@9999years

Description

@9999years

Sometimes, jj errors out after 'failing to reset Git HEAD state':

$ jj status
Error: Failed to reset Git HEAD state
Caused by:
1: Could not acquire lock for index file
2: The lock for resource '/my/repo/.git/index' could not be obtained immediately after 1 attempt(s). The lockfile at '/my/repo/.git/index.lock' might need manual deletion.

We see this error pretty frequently, but we do not yet have a good reproducer.

In general, it is not obvious why this issue occurs or what causes it.

Workaround

Like the message says, rm .git/index.lock seems to work, although we'll also frequently need to run jj workspace update-stale and resolve a conflicted revision.

Clues

What follows are some clues that may or may not be relevant.

git status still works

Even if jj can't get the lock to run jj status, git status computes the working changes correctly.

git maintenance is not running

Unlike #7210 (comment), we do not have git maintenance enabled or running.

fsmonitor is watchman

We do have the watchman fsmonitor enabled, scoped to the repo to work around #5817:

fsmonitor.watchman.register-snapshot-trigger = true

[[--scope]]
--when.repositories = [
    "/my/repo",
]
fsmonitor.backend = "watchman"

lsof is uninteresting

nvim seems to be holding a reference to the .git/HEAD, but not the index. This seems to be present regardless of if the bug is occurring, but it's definitely something to investigate.

$ lsof | head -n1; lsof | rg "/my/repo/.git"
COMMAND     PID    USER  FD     TYPE             DEVICE   SIZE/OFF                NODE NAME
nvim      67118 wiggles  15r     REG               1,19         41           128747037 /my/repo/.git/HEAD

Specifications

  • Platform: macOS Tahoe 26.0
  • Version: jj 0.33.0

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions