Skip to content

Commit 1c284e4

Browse files
committed
Fix cache copy lock to use frozenset key instead of first path
The lock was keyed on only the first sorted path, causing unrelated sets sharing a first path to serialize, and overlapping sets with different first paths to not deduplicate.
1 parent 023d35f commit 1c284e4

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

pkgs/nixkube/src/cache.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
logger = logging.getLogger("nixkube.cache")
1414

15-
# Locks that prevent the same derivation to be uploaded in parallel
16-
copy_lock: defaultdict[Path, Semaphore] = defaultdict(Semaphore)
15+
# Locks that prevent the same set of paths from being uploaded in parallel
16+
copy_lock: defaultdict[frozenset[Path], Semaphore] = defaultdict(Semaphore)
1717

1818

1919
async def check_cache_connectivity() -> bool:
@@ -67,9 +67,7 @@ async def copy_to_cache(package_paths: set[Path]) -> None:
6767

6868
logger.debug(f"copy_to_cache: starting for {len(package_paths)} packages")
6969

70-
# Create a lock key from all paths to prevent concurrent copies of the same set
71-
lock_key = tuple(sorted(package_paths))
72-
async with copy_lock[lock_key[0] if lock_key else Path("")]:
70+
async with copy_lock[frozenset(package_paths)]:
7371
paths: set[Path] = {Path(p) for p in package_paths}
7472

7573
# Get regular closure paths for all packages

0 commit comments

Comments
 (0)