Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Promise not completing if timeout is reached #43

Open
martinhyldgaard opened this issue Sep 15, 2017 · 0 comments
Open

Promise not completing if timeout is reached #43

martinhyldgaard opened this issue Sep 15, 2017 · 0 comments

Comments

@martinhyldgaard
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant