Skip to content

get with redirect leads to ~30sec hang #435

@stephematician

Description

@stephematician

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions