Skip to content

fix(package): give each Forge build a staging base it owns - #69

Merged
stuffbucket merged 1 commit into
mainfrom
fix/packager-private-staging-base
Sep 7, 2026
Merged

stuffbucket merged 1 commit into
mainfrom
fix/packager-private-staging-base

Conversation

@stuffbucket

Copy link
Copy Markdown
Owner

main is red at 6d8f346, and #57 is red with the same error naming a different file. Neither is a dependency break — which is exactly what the failing pull requests made it look like.

The bug

@electron/packager derives its staging base from a constant:

// common.js
baseTempDir(opts) {
  return path.join(opts.tmpdir || os.tmpdir(), 'electron-packager')
}

// packager.js
async ensureTempDir() {
  if (this.useTempDir) {
    await fs.remove(this.tempBase)   // the whole shared directory, every run
  }
}

The directory inside that base is already unique — stagingPath calls mkdtemp, which is where tmp-TRr4aR comes from — so uniqueness is not what is missing. The unconditional wipe of the shared parent is what throws it away.

Since #45, CI packages two applications rather than one (ci.yml: "Two Forge builds, not one"). So the second build deletes the first's staged tree while asar is midway through reading it. asar crawls, lstats every path, then opens each in turn, so the loss surfaces as ENOENT on a file it had already stat'ed — whichever file it reached at that instant.

That accounts for the whole symptom set:

Observed Because
resources/app/package.json on main, node_modules/minipass/LICENSE.md on #57 whatever asar was reading when the wipe landed
Failing package moves between maximal-electron and maximal-client whichever build started first loses
lstat succeeds, open ENOENTs, same process the tree is deleted between crawl and read
Green locally, red in CI one build locally; two concurrently in CI
Red on main with no Electron bump nothing to do with any dependency

The fix

mkdtemp one level up, in both applications. Packager still wipes the base, but it is one this build created and owns, and move() relocates the finished build into out/, so nothing accumulates there.

Both applications must set it. One alone still leaves the other wiping a directory it does not own.

Verification

Planting another build's staging tree at the shared path — the exact path from the CI error — and running a package:

without this change   sentinel GONE
with this change      sentinel PRESENT

No timing dependence: the wipe is unconditional, so this is deterministic rather than a race that has to be caught. Separately, a packaged run with this change creates no electron-packager base at all, staging under forge-maximal-electron-AAbIdm instead.

tsc --noEmit and eslint pass in both packages. The real check is this branch's own electron package job, which exercises the two concurrent builds that were colliding.

Worth reporting upstream

A fixed, shared temp base that is rm -rf'd once per run makes concurrent @electron/packager invocations unsafe for anyone, not just this repository.

`main` is red at 6d8f346 with

    ENOENT: no such file or directory, open
    '/tmp/electron-packager/tmp-TRr4aR/resources/app/package.json'

and #57 is red with the same error naming a different file. Neither is a
dependency break, which is what the failing pull requests made it look like.

@electron/packager derives its staging base from a constant:

    baseTempDir(opts) {
      return path.join(opts.tmpdir || os.tmpdir(), 'electron-packager')
    }

and `ensureTempDir` runs `fs.remove` over the whole of it at the start of
every run. The directory *inside* that base is already unique -- `stagingPath`
calls `mkdtemp`, which is where `tmp-TRr4aR` comes from -- so uniqueness is
not what is missing. The unconditional wipe of the shared parent is what
throws it away.

Since #45 CI packages two applications rather than one, so the second Forge
build deletes the first's staged tree while asar is midway through it. asar
crawls, `lstat`s every path, then opens each in turn, so the loss surfaces as
ENOENT on a file it had already stat'ed -- whichever file it reached at that
instant, in whichever application started first. That is why the named file
and the failing package move between runs, and why it reads as a break in
whatever happens to be under review.

Fixed by mkdtemp one level up, in both applications. Packager still wipes the
base, but it is one this build created and owns, and `move()` relocates the
finished build into `out/`, so nothing accumulates there.

Verified by planting another build's staging tree at the shared path and
running a package:

    without this change   sentinel GONE
    with this change      sentinel PRESENT

and by confirming a packaged run creates no `electron-packager` base at all,
staging under `forge-maximal-electron-AAbIdm` instead. Both applications must
set it; one alone still leaves the other wiping a directory it does not own.
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.

1 participant