hgouveia / node-downloader-helper

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

Bug report and a potential solution: ECONNRESET error #113

Open cocktailpeanut opened 6 months ago

cocktailpeanut commented 6 months ago

Been trying to debug why I'm getting ECONNRESET errors occasionally.

What I found was the following:

1 .The ECONNRESET error doesn't always result in dl.start() throwing. Often this results in the downloader retrying the request.

  1. But sometimes it just halts with ECONNRESET.
  2. When it halts with ECONNRESET, I've found that it doesn't even get to the redirect step (The URL i'm fetching involves a redirect).

Based on this, I've come to a conclusion that the ECONNRESET is happening at the HEAD step inside the getTotalSize(). It triggers the "error" event here: https://github.com/hgouveia/node-downloader-helper/blob/master/src/index.js#L365

Basically, I think this specific case of ECONNRESET is happening during the HEAD step and there is no handling logic to retry.

My current solution is to just retry the dl.start() multiple times until it eventually works. But I feel like this should be handled by the library, perhaps take a separate retryHead attribute that does the same thing as retry, but for the getTotalSize() request.