zkat/make-fetch-happen

Promise not completing if timeout is reached

martinhyldgaard opened this issue · 0 comments

When fetching with a timeout set, and the server takes longer than the timeout to reply, it seems the promise does not complete.

Code to reproduce:

    //const fetch = require('node-fetch');
    const fetch = require('make-fetch-happen').defaults();
    fetch('http://localhost:4567/', {timeout:6000}).then(console.log).catch(console.log);

When using node-fetch promise is rejected and the catch is reached on timeout. I've used this mountebank imposter to test:

{
    "protocol": "http",
    "port": 4567,
    "numberOfRequests": 1,
    "requests": [],
    "stubs": [
        {
            "predicates": [
                {
                    "deepEquals": {
                        "method": "GET"
                    }
                },
                {
                    "deepEquals": {
                        "path": "/"
                    }
                }
            ],
            "responses": [
                {
                    "is": {
                        "statusCode": 200,
                        "headers": {
                            "Content-Type": "text/plain"
                        },
                        "body": "success"
                    },
                    "_behaviors": {
                        "wait": 7000
                    }
                }
            ]
        }
    ]
}

If the wait of the imposter is lowered to below the timeout the code completes as expected, with promise accepted