hgouveia / node-downloader-helper

A simple http file downloader for node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not respecting `RemoveOnStop` config flag.

umerkk opened this issue · comments

Sporadically the library goes into a state where Stopping the download would trigger the Remove action on the Downloaded file even if the library is instantiated with the RemoveOnStop: false flag.

Here is my instantiation code

    this.helper = new NodeDownloadHelper(metadata.source,
      metadata.destination,
      {
        forceResume: false,
        override: false,
        removeOnFail: false,
        removeOnStop: false,
        retry: false,
        httpRequestOptions: {
          timeout: Config.DOWNLOADS.TIMEOUT,
        },
        httpsRequestOptions: {
          timeout: Config.DOWNLOADS.TIMEOUT,
        },
      });

Logs

{"moduleName":"Node Downloader for af293d87-a90d-490d-ad27-4ee2905aae02","level":"info","message":"[ 'Download stopped' ]","timestamp":"2021-04-20T10:48:35.219Z"}


{"moduleName":"Node Downloader for af293d87-a90d-490d-ad27-4ee2905aae02","level":"info","message":"[ 'Download stopped' ]","timestamp":"2021-04-20T10:48:35.219Z"}
{"level":"error","message":"Unhandled promise rejection, reason: ENOENT: no such file or directory, stat '/var/folders/gm/713hkdtn60j5kpkht_fh1yph0000gp/T/unityhub-e57c7420-a1c5-11eb-9147-0d5d8a32fca5/UnitySetup-AppleTV-Support-for-Editor-2018.4.33f1.pkg'\n\tstack Error: ENOENT: no such file or directory, stat '/var/folders/gm/713hkdtn60j5kpkht_fh1yph0000gp/T/unityhub-e57c7420-a1c5-11eb-9147-0d5d8a32fca5/UnitySetup-AppleTV-Support-for-Editor-2018.4.33f1.pkg'\n    at statSync (fs.js:1020:3)\n    at Object.e.statSync (electron/js2c/asar_bundle.js:5:4264)\n    at b.d (/Users/antoine.lheureux/dev/unity/hub.uw-hub/dist/mac/Unity Hub.app/Contents/Resources/app.asar/node_modules/node-downloader-helper/dist/index.js:1:13483)\n    at WriteStream.<anonymous> (/Users/antoine.lheureux/dev/unity/hub.uw-hub/dist/mac/Unity Hub.app/Contents/Resources/app.asar/node_modules/node-downloader-helper/dist/index.js:1:9440)\n    at WriteStream.emit (events.js:327:22)\n    at WriteStream.EventEmitter.emit (domain.js:483:12)\n    at internal/fs/streams.js:247:14\n    at /Users/antoine.lheureux/dev/unity/hub.uw-hub/dist/mac/Unity Hub.app/Contents/Resources/app.asar/node_modules/graceful-fs/graceful-fs.js:61:14\n    at FSReqCallback.oncomplete (fs.js:160:23)","timestamp":"2021-04-20T10:48:35.225Z"}

Hello @umerkk , i was checking this issue but i can't find the reason, i was wondering if the destination folder is a temp folder or something that is cleaned automatically? could you try a different folder?

also could you verify the folder and check if the file is there? i was thinking could be a permission issue too

i will keep checking it

Hi @hgouveia
The problem exists at any arbitrary location, I tried OS temp, User Download, and other folders.
It happens sporadically, so the permission doesn't seem to be an issue since it is successfully downloading there most of the time.

Although to reproduce, you may want to pause/resume a download multiple times. Also, try to disable the internet, then let the download fail, retry multiple times (which will also fail as the network is not available), and then try to stop.
It should go into the state I mentioned above after several tries.

Hello @umerkk, it seems the issue was not related with RemoveOnStop but with some functionallity that was triggered to calculate the filesize when finished, sometimes this event is triggered even when aborted so it seems was causing the error, i fixed it on #53, hopefully should fix this issue

Implemented on v2.1.0