Skip to content

Issue with asar packaging (after 'prolonged' use, files start to ENOENT)  #2871

Closed

Description

@marwanhilmi

This issue occurs on both Electron v30.0 and v33.0 but only reproducible on Windows (x64). We have tested extensively on OSX and can't reproduce but Windows 32-bit and Linux are untested.

Essentially we have an application with lots of image resources packaged into the .asar archive. Our application will frequently load images from the archive - depending on state in our application, we completely unload assets from memory so we are often re-requesting them. We have used both XHR + file:// requests and the fs module directly and the result is the same.

After some time (ie continued / frequent requests of assets) - the files start to ENOENT as if they don't exist. Once the files start to ENOENT, they can never be read again unless the application is restarted. How long this takes to occur may vary but it is almost 100% reproducible for us.

If we disable asar packing and just bundle without the asar, the issue does not occur.

Not clear if the issue lies inside Electron's asar.coffee or the asar implementation itself. It does not appear the asar archive becomes corrupt (as it works fine when you restart) but something is breaking the reading of files.

You basically see something like below, despite the fact that all the files obviously exist:

vendor.js:11 Error: ENOENT, src\resources\units\neutral_beastdarkharbinger.png not found in C:\Users\m\app\v1.0.18\resources\app.asar(…)
vendor.js:11 Error: ENOENT, src\resources\units\neutral_golembloodshard.png not found in C:\Users\m\app\v1.0.18\resources\app.asar(…)
vendor.js:11 Error: ENOENT, src\resources\units\neutral_mechaz0rcannon.png not found in C:\Users\m\app\v1.0.18\resources\app.asar(…)
vendor.js:11 Error: ENOENT, src\resources\units\neutral_chaoselemental.png not found in C:\Users\m\app\v1.0.18\resources\app.asar(…)
vendor.js:11 Error: ENOENT, src\resources\units\neutral_monsteroculus.png not found in C:\Users\m\app\v1.0.18\resources\app.asar(…)
vendor.js:11 Error: ENOENT, src\resources\units\neutral_golem_crossbones.png not found in C:\Users\m\app\v1.0.18\resources\app.asar(…)
vendor.js:11 Error: ENOENT, src\resources\units\neutral_golemstone.png not found in C:\Users\m\app\v1.0.18\resources\app.asar(…)

I can try to write up a standalone test case that reproduces this behavior if necessary.
Just again tested on 33.1 (noting the other bug fix in the asar code) but it still happens.

Activity

  1. zcbenz commented on Sep 23, 2015

    @zcbenz
    Contributor

    A test case would be awesome, it is quite mysterious to me since the asar code is exactly the same on all platforms.

  2. marwanhilmi commented on Sep 23, 2015

    @marwanhilmi
    Author

    @zcbenz I'll try wire up a test case that emulates our actual usage but it'll take a little while - I can Skype/Hangout with you and demo you the issue from our actual application. Nonetheless, will try to write up a test case.

    Note @cluxter, at first we thought this was an issue with FDs leaking but we do not get EMFILE errors, the files 'disappear' with ENOENT. My experience debugging on Windows is pretty limited but used Sysinternals tools to inspect the open file descriptors and there does not appear to be anything out of the ordinary there.

    I'm not sure if Windows has a hard limit on FDs similar to *nix that can configured with ulimit -n, any ideas on this @zcbenz ?

  3. kevinsawicki commented on Sep 23, 2015

    @kevinsawicki
    Contributor

    @zcbenz I was just looking at d8d7e5b#diff-ace709cf496d188d302a87b24d26e383R271 which calls _open_osfhandle.

    Do those handles returned need to be eventually closed somehow? Could they possibly be leaking when archive.getFd() occurs a lot and then causing EMFILE errors to be masked as ENOENT issues inside asar?

  4. marwanhilmi commented on Sep 23, 2015

    @marwanhilmi
    Author

    If anyone has suggestions on how to test / count file descriptors on Windows, I can definitely investigate further. From my initial debugging, it was difficult to tell if I had reached a limit (not even really sure how/what this limit is on Windows). It does appear that the asar code will gobble up the errors and just return ENOENT but cannot confirm.

  5. kevinsawicki commented on Sep 23, 2015

    @kevinsawicki
    Contributor

    Okay, I was able to reduce this a bit and reproduce on Windows 8.1 using Electron 0.33.1 64-bit:

    Run the following from the dev tools in the default Electron app:

    for(var i = 0; i < 10000; i++) require('fs').readFileSync(require('path').join(process.resourcesPath, 'atom.asar', 'renderer', 'api', 'lib', 'ipc.js'))

    The ENOENT errors seems to start after around ~3,000 fs.readFileSync calls.

    Here is a screenshot showing it working the first time, then trying to call it over and over in loops of 1000 and then it stops working altogether:

    screen shot 2015-09-23 at 4 39 32 pm

    Here is the stack trace when it starts happening:

    Uncaught Error: ENOENT, renderer\api\lib\ipc.js not found in C:\Users\kevin\Downloads\electron-v0.33.1-win32-x64\resources\atom.asar
      notFoundError @ ATOM_SHELL_ASAR.js:104
      fs.readFileSync @ ATOM_SHELL_ASAR.js:416
    
  6. zcbenz commented on Sep 24, 2015

    @zcbenz
    Contributor

    Do those handles returned need to be eventually closed somehow? Could they possibly be leaking when archive.getFd() occurs a lot and then causing EMFILE errors to be masked as ENOENT issues inside asar?

    It is exactly the cause of this bug, great job!

  7. cluxter commented on Sep 24, 2015

    @cluxter

    Thanks a lot guys! I hope the v1.0.17 for Windows will be out soon so we can test it. Also the v1.0.16 is not usable on Windows so this is quite important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions