Skip to content

Commit 66611b6

Browse files
committed
chore: anchor flock under config dir
On CI/Windows, repository contention started flaking after tests began isolating TMP per process. Our flock files lived in os.TempDir(), so each process used a different lock root and we effectively had no cross-process locking. Concurrent git remote add/set-url against the same .git/config then raced and intermittently failed. Signed-off-by: Guillaume de Rouville <guillaume@dagger.io>
1 parent 0c0cc77 commit 66611b6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

repository/flock.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ func (rlm *RepositoryLockManager) GetLock(lockType LockType) *RepositoryLock {
5757
return lock
5858
}
5959

60+
lockRoot := os.Getenv("CONTAINER_USE_CONFIG_DIR")
61+
if lockRoot == "" {
62+
lockRoot = getDefaultConfigPath()
63+
}
6064
lockFileName := fmt.Sprintf("container-use-%x-%s.lock", hashString(rlm.repoPath), string(lockType))
61-
lockDir := filepath.Join(os.TempDir(), "container-use-locks")
65+
lockDir := filepath.Join(lockRoot, "locks")
6266
lockFile := filepath.Join(lockDir, lockFileName)
6367

64-
err := os.MkdirAll(lockDir, 0755)
65-
if err != nil {
66-
slog.Error("Failed to create lock directory", "error", err)
67-
}
68-
69-
lock := &RepositoryLock{
70-
flock: flock.New(lockFile),
68+
if err := os.MkdirAll(lockDir, 0o755); err != nil {
69+
slog.Error("Failed to create lock directory", "path", lockDir, "error", err)
7170
}
7271

72+
lock := &RepositoryLock{flock: flock.New(lockFile)}
7373
rlm.locks[lockType] = lock
7474
return lock
7575
}

0 commit comments

Comments
 (0)