Skip to content

[Feature Request]: close asar manually #28368

Open

Description

@nomagick

Asar fd not closed on windows after use (by sandboxed renderer).
A lock was held by the main process, preventing the file to be removed.

Proposed Solution

Implement asar cache management and expose public API to allow asar files be closed manually.

#28195 was not fixed by #28137.

As of v12.0.2, there were issue with asar file fd handling on Windows.

The file would be kept open by the main process once used, and no way to close it.

#28195 was previously submitted, but NOT resolved by #28137.

Maybe It's time to provide a public API to manage asar files.

In my scenario, ASAR files was to be used as plugin packages, thus needs to be replaced or removed when process is still running.
It seems ok to do it on macOS , but not on Windows.

I guess some of asar related code is to be refactored, so please consider this proposal.

Thanks.

Activity

  1. aprilandjan commented on May 18, 2021

    @aprilandjan

    I'm using macOS and electron v11.4.1. Found that if the renderer window load some resources(image, for example) which located in the asar bundle, the main process will keep file descriptors of the asar file, and it seems it will never be disposed. Whille using, the asar file descriptors opened by the main process will be more and more.

    This should be solved, the leak of the asar file descriptors might be a problem.

  2. nomagick commented on May 18, 2021

    @nomagick
    Author

    I currently walk around this issue by overriding the file protocol handler.
    Then fetch and return contents of asar through my own pure javascript asar IO implementation.

  3. aprilandjan commented on May 18, 2021

    @aprilandjan

    @nomagick can you please share how to do the overriding? I'm trying to configure electron-builder to exclude the modules which holding images from asar bundle, but still be able to require the module as usual. Seems no luck currently 😢

  4. nomagick commented on May 19, 2021

    @nomagick
    Author

    @aprilandjan https://www.electronjs.org/docs/api/protocol#protocolinterceptfileprotocolscheme-handler

    However the main app.asar file is more special because browser process node.js load resources from it too.
    So it's not likely that the main app.asar could be modified while running.
    If you are trying to achieve update by swaping app.asar, that probably will not work.

  5. aprilandjan commented on May 19, 2021

    @aprilandjan

    @nomagick thanks for your advise, I'll try the protocol api 🙏

  6. gpetrov commented on May 19, 2021

    @gpetrov

    Maybe a solution is to leave your images in the app.asar.unpacked folder. You can achieve this by specify --unpack-dir to the asar pack command. It will then just leave store them in the app.asar.unpacked folder - that will be logically merged with your regular asar folder.

    I had to do this will native modules and binary executables, which also have problems when loaded from asar.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions