needle icon indicating copy to clipboard operation
needle copied to clipboard

`get` with redirect leads to ~30sec hang

Open stephematician opened this issue 7 months ago • 7 comments

I'm trying to download a file (or other 'get' requests) which have redirects, but they seem to hang for some time. E.g. let's say I use a promise to download a file:

function get_file(url: string, file_path: string) : Promise<void> {

    return new Promise<void>((resolve, reject) => {
        needle.get(
            url, { follow_max: 1, output: file_path },
        (error) => {
            if (error) { reject(error); }
            resolve();
        })
    }); 

}

async function foo() : Promise<void> {
    await get_file(
        "https://github.com/tomas/needle/archive/refs/tags/v3.2.0.zip",
        "foo.zip"
    );
    console.log("So we should be done here.");
}

foo();
// > So we should be done here.
// then a 30 second delay (roughly) before the program exits

The only way around this that I've had luck with, so far, is to attach a signal to the request and abort it after the file has downloaded.

It seems to be an issue when following? Because if I download a file that doesn't require a redirect, there isn't any delay before the program ends.

stephematician avatar Jun 29 '24 08:06 stephematician