sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Timeout not thrown with wrong https url, port, http2 enabled #1492

Closed asomethings closed 3 years ago

asomethings commented 4 years ago

Describe the bug

Request to a url which starts with https, url with port ends up with pending forever. Since timeout error is thrown well with https, wrong url, http2 enabled, I think it should throw timeout error instead of pending forever with https, wrong url, port, http2 enabled too. Also i acknowledge that using https with port is an rare use case but still i think it should behave the same as others.

Actual behavior

Promise pends forever.

Expected behavior

Below error should be thrown after 500ms

RequestError: Timeout awaiting 'request' for 500ms

Code to reproduce

got('https://www.example.com:8800', {
  method: 'POST',
  http2: true,
  responseType: 'buffer',
  timeout: 500,
  retry: {
    limit: 0,
  },
})

Checklist

ssypi commented 3 years ago

It's not just a wrong port, this also happens for me if the url resolves to an ip, but it is unconnectable for example due to a firewall or just doesn't have anything that would respond to it. I tried to upgrade to http-wrapper@2.0 mentioned in #1637 but same thing. EDIT: Oh the latest got already has it updated to 2.0, no wonder it didn't change anything.

got("https://123.123.123.123", {
    timeout: 1000,
    http2: true,
})
    .then(() => console.log("success"))
    .catch(() => console.log("fail"));

Takes like 2 minutes to resolve on my machine. But if I set http2 to false, it times out quickly. Even if I use cancel() on the request, the catch will get called with error, BUT the connection(?) still stays open and it keeps the node process open for the full duration until it times out after a minute or two.