Skip to content

lockfile: CleanupAll/CleanupStaleLocks still unlock before unlink #6713

Description

@jhrozek

Follow-up from #6711 review (#6711 (review)).

AcquireTrackedLock/ReleaseTrackedLock in pkg/lockfile/cleanup.go were fixed to close the unlock/unlink release race (unlink before unlock, plus an inode-identity check on acquire) for the normal WithFileLock path.

CleanupAll (process-exit cleanup) and CleanupStaleLocks (startup stale-lock sweep, which includes the secrets-store directory) still do unlock-then-remove, and don't go through AcquireTrackedLock's identity check. Per jaormx: "A waiter can acquire and pass the inode check between those steps, then have its lock pathname removed while another process locks a replacement inode... this isn't just an unused helper."

Scope: reorder both to unlink-before-unlock, and decide whether they should route through AcquireTrackedLock for the identity check where applicable (CleanupStaleLocks uses TryLock on an already-stale-by-age file, so the tradeoffs may differ from the normal acquire path).

Activity

  1. suantea commented on Oct 10, 2026

    @suantea

    I'd like to take this one. The fix is straightforward: change CleanupAll and CleanupStaleLocks to unlink (os.Remove) before unlocking, matching the race-safe order in ReleaseTrackedLock's comment (flock locks inodes, not paths). Happy to have it assigned.

  2. suantea commented on Oct 11, 2026

    @suantea

    Updated PR #6794 with unlink-before-unlock for CleanupAll and CleanupStaleLocks in pkg/lockfile/cleanup.go (matches ReleaseTrackedLock order). Tests pass and build is clean.

  3. suantea commented on Oct 11, 2026

    @suantea

    Follow-up in PR #6794 updates the unlink-before-unlock ordering in CleanupAll and CleanupStaleLocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageIssue needs initial triage by a maintainer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions