hgouveia / node-downloader-helper

A simple http file downloader for node.js
MIT License
247 stars 54 forks source link

Download hangs out if connection drops mid-progress and and doesn't emit any sign #78

Closed mohamed94eda closed 2 years ago

mohamed94eda commented 2 years ago

Download hangs out if connection drops mid-progress and and doesn't emit any sign, when connection come back it still hanging .

`let options = { retry: { maxRetries: 5, delay: 2500 }, override: true, removeOnFail: true, progressThrottle: 1000,

};`

hgouveia commented 2 years ago

hello @mohamed94eda it seems this is similar issue than #11 , it seems to be related with some issue with nodejs itself that has been reported before but i am still unable to figure out a solution, but could you try adding a timeout to see what happens ?

mohamed94eda commented 2 years ago

I did add the on('timeout)

But it doesn't get invoked either.

I noticed if connection drops for +60 sec this happens.

But if less than +-60 sec the download resumes as expected

hgouveia commented 2 years ago

@mohamed94eda you need to add the timeout to the options you have, like this

const timeout = 1000 * 10; // 10 seconds
const options = {
    retry: { maxRetries: 5, delay: 2500 },
    override: true,
    removeOnFail: true,
    progressThrottle: 1000,
    httpRequestOptions: { timeout },
    httpsRequestOptions: { timeout },
}
mohamed94eda commented 2 years ago

It does invoke the retrying attempts, but then throws an err ENOENT : no such file or directory

I can workaround it by settingremoveOnFail: false

mohamed94eda commented 2 years ago

It does invoke the retrying attempts, but then throws an err ENOENT : no such file or directory

I can workaround it by settingremoveOnFail: false

Tried to refactor my code and increase the timeout you mentioned and yes it does workaround the issue, maybe include the timeout as an option in your package, great finding

hgouveia commented 2 years ago

@mohamed94eda glad to here! yeap probably i will include it as a single timeout option instead of httpsRequestOptions: { timeout } in the future! Thanks for the suggestion,

closing this