Skip to content

[Bug]: createReadStream fails for ASAR entry after extracted temp file is deleted #52804

Closed

Description

@0xdevalias

Preflight Checklist

Electron Version

43.4.0

What operating system(s) are you using?

macOS

Operating System Version

macOS 26.6 (25G72)

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

Unknown

Does the issue also appear in Chromium / Google Chrome?

No. This is specific to Electron's ASAR filesystem integration.

Expected Behavior

After a temporary copy of a packed ASAR entry is removed while Electron remains running, a later fs.createReadStream() call for that ASAR entry should recreate the temporary copy or otherwise read the packed bytes successfully.

Actual Behavior

The first fs.createReadStream() succeeds. If its extracted temporary file is then deleted while Electron remains running, every later fs.createReadStream() for the same ASAR entry fails with ENOENT for the deleted temporary pathname. A buffered fs.readFileSync() of the same packed entry continues to succeed.

Example output from the testcase:

Extracted copy: /var/folders/.../T/.com.github.Electron.ul88vz
Deleted the extracted copy while Electron remains running.
readFileSync after deletion: "electron-asar-stale-cache-repro-7e8fa4f9\n"
REPRODUCED: ENOENT opening cached path /var/folders/.../T/.com.github.Electron.ul88vz

Testcase Gist URL

https://gist.github.com/0xdevalias/b28e27ea290913bbe4510eeaad7edaf3

Run with:

git clone https://gist.github.com/b28e27ea290913bbe4510eeaad7edaf3.git
cd b28e27ea290913bbe4510eeaad7edaf3
npm install
npm start

Additional Information

This was first encountered in openai/codex#37551, where a long-running Electron process could no longer open Codex windows after its extracted .com.openai.codex.* ASAR files disappeared. The original packed entries remained readable, and recreating the expected temporary files restored the running application. The validated diagnosis and workaround are documented in openai/codex#37551 (especially this investigation comment and the upstream-context follow-up).

This report is specifically about recovery from a missing cached extraction file, rather than whether temporary files should be cleaned up at process exit.

Related prior reports:

In-depth investigation

Archive::CopyFileOut() retains extracted files in external_files_. Its cache-hit branch returns the stored pathname without checking whether it still exists:

Electron's Node filesystem wrapper calls archive.copyFileOut() from its fs.open() override. fs.createReadStream() reaches that wrapper, so a later stream open receives the stale pathname and the underlying OS open fails with ENOENT:

The standalone testcase uses only the public fs behavior to trigger the failure. It locates the first extracted copy by its unique contents, deletes it, confirms readFileSync() can still read the original packed bytes, and then observes createReadStream() failing against the same deleted pathname.

Electron's own ASAR URL loader already avoids extraction for packed entries and streams from a duplicate of the archive's retained file handle. PR #52283 similarly made retained-handle reads robust when an updater atomically replaces app.asar. Neither path repairs a missing CopyFileOut() cache entry.

A minimal fix could check the cached path under external_files_lock_, evict the entry when it no longer exists, and extract it again. A fully race-resistant solution may also need retry/invalidation if the file disappears between an existence check and the consumer's subsequent open().

Activity

  1. added
    has-repro-gist
    on Aug 13, 2026
  2. moved this to 👀 Unsorted Items in 43-x-yon Aug 13, 2026
  3. added a commit that references this issue on Aug 14, 2026
    ebdb1bc
  4. 0xdevalias commented on Aug 18, 2026

    @0xdevalias
    Author

    It looks like @codebytere opened a PR with a bugfix for this, but later closed it:

    Currently not sure of the context around that, but asked for clarity in this comment:


    Edit: Some further context:

    @codebytere I see that #52811 looks like it was a testing bug you ran into after creating this PR, and that it landed; but from what I saw there, it didn't look like it contained this PR or a related fix; so I am curious why you closed this PR, if there is another newer/rebased/etc version of this fix I should be watching for; and/or whether you just found that this wasn't actually a good solution to #52804, etc


    Edit: After exploring with GitHub Copilot (GPT-5.6 Terra), I believe this may have been closed because there is a more broader PR related to ASAR file improvements/etc:

    Best evidence: PR #52807 appears to have been closed in favor of the broader, still-open PR #52833, but there is no explicit closure explanation or cross-reference confirming that. The original issue, #52804, is still open, so the fix has not landed yet.

    #52833 changes the relevant architecture instead of repairing the stale cache. It removes Archive::CopyFileOut() from fs.open, fs.createReadStream, fs.promises.open, descriptor reads, streams, and copy APIs. Packed ASAR entries are read directly from a duplicated retained archive FD, so there is no extracted temp file for macOS to sweep away.

    That directly solves the reported createReadStream / fs.open stale-temp-file failure in #52804, more comprehensively than #52807’s “check whether the cached extracted path still exists; re-extract if not” approach.

    However, #52833 is not a perfect one-for-one replacement. It explicitly leaves child_process.execFile*, process.dlopen, and native-module loading on the temp-copy path because they require a real OS path. So #52833 addresses the issue’s createReadStream case, but apparently does not address #52807’s broader claim that execFile should recover after its cached temp copy disappears.

    Originally posted by @0xdevalias in #52807 (comment)

  5. moved this from 👀 Unsorted Items to 👍 Does Not Block Stable in 43-x-yon Aug 19, 2026
  6. codebytere commented on Aug 23, 2026

    @codebytere
    Member

    @0xdevalias #52807 was closed because #52833 removes the temp-copy path entirely (fds, streams and copies are served from the archive now), which fixes this at the source. that's landed for 45; it's too large to backport, so 43/44 keep the current behaviour.

  7. 0xdevalias commented on Aug 24, 2026

    @0xdevalias
    Author

    @codebytere Thanks for confirming, and awesome that it's landed for future versions! No worries about not being able to backport.

  8. added theissue type on Sep 16, 2026
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

    43-x-ybug 🪲has-repro-gistplatform/macOS

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions