Skip to content

fix: make concurrent first use of packages race-free - #647

Merged
alecthomas merged 3 commits into
masterfrom
aat/fix-concurrent-install-races
Nov 19, 2026
Merged

alecthomas merged 3 commits into
masterfrom
aat/fix-concurrent-install-races

Conversation

@alecthomas

@alecthomas alecthomas commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Concurrent first uses of packages fail intermittently in bit's CI with <pkg>: unknown package or stat <cache archive>: no such file or directory. This fixes the three races behind them.

  • Manifest syncs weren't serialised. Every process that missed a package re-synced the shared checkout, and concurrent clones replaced it while others read it. Syncs now take a per-source lock and skip if another process just synced.
  • A channel package's first use counted as an overdue update. Every process evicted the cached archive and package and reinstalled them while others were extracting that archive. First uses now just record the check. Upgrades download over the archive instead of evicting it, and skip versions another process already installed.
  • Git package sources cloned straight into the cache, so other processes copied partial clones. They now clone to a temporary directory and rename it into place.

In Linux Docker trials of 16 or 32 concurrent first uses, the original build failed up to 18 of 20 trials. The fixed build had no failures in 160 trials. Each race has a regression test that fails on the original code, including a multi-process integration test.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

alecthomas and others added 3 commits November 19, 2026 00:21
Concurrent first uses of Hermit packages failed intermittently on
Linux CI with "unknown package" or "stat <cache archive>: no such file
or directory".

Manifest syncs were unserialised. Every process that missed a package
forced a sync, and concurrent clones or failed pulls deleted and
replaced the shared checkout while other processes read it. Syncs now
take a per-source lock, skip if another process synced while they
waited, and move the old checkout aside instead of deleting it.

The first use of a channel package counted as an overdue update with
an unknown ETag, so every process evicted the cached archive and
unpacked package, then reinstalled them, while others were about to
extract that archive. First uses now record the check, and upgrades
download over the archive instead of evicting it and skip reinstalling
a version another process already installed.

Git package sources cloned straight into the cache, so concurrent
processes copied partial checkouts. They now clone into a temporary
directory and rename it into place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The linter config doesn't flag exec.Command in tests, so nolintlint
reported these directives as unused and failed the Lint check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A process that downloads a channel package outside the lock can find
it already extracted by a process that used its download from the
cache without knowing its ETag. Neither recorded the ETag, so the
first channel check recorded an empty one, and its unlocked write
could also overwrite a real one. A later check would then reinstall
the package.

The downloading process now records the ETag even when it didn't
extract the package, and the first check records its state under the
lock after reading it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alecthomas
alecthomas merged commit ec8dcf3 into master Nov 19, 2026
8 checks passed
@alecthomas
alecthomas deleted the aat/fix-concurrent-install-races branch November 19, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants