Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeouts are longer than expected #2332

Open
2 tasks done
guillenotfound opened this issue Feb 21, 2024 · 1 comment
Open
2 tasks done

Timeouts are longer than expected #2332

guillenotfound opened this issue Feb 21, 2024 · 1 comment

Comments

@guillenotfound
Copy link

guillenotfound commented Feb 21, 2024

Describe the bug

  • Node.js version: v21.5.0
  • OS & version: macOs 14.2 (23C64)

Actual behavior

The request is taking longer to respond but the timings in the error object look correct:
image

When executing the sample code, execution is taking above 6 seconds even if the timeout is 1.

Expected behavior

The request should last ~1000ms, it can be a few milliseconds more due to processing time, let's say max 1010ms.

Code to reproduce

import got from 'got'

;(async () => {
  const start = new Date()
  const res = await got('https://httpbin.org/delay/10', { timeout: { request: 1000 } }).catch(err => err)
  const end = new Date()
  console.log(res)
  console.log({ diff: (end - start) / 1000 })
})().catch(console.error)

// Output:
// ... error
// { diff: 6.185 }

I also have this in my tsconfig.json:

    "paths": {
      "got": ["./node_modules/got/dist/source"]
    }

I've also tested this scenario with a brand new project and latest Got and I'm able to reproduce.

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@masontikhonov
Copy link

Hi @guillenotfound, it seems you're observing such a behavior because of retry mechanism, which, by default, retries requests that timed out up to 5 times (please check retry documentation). That's why total execution time is longer than you're expecting. At the same time, timings in error, in my understanding, reflects the timings for the latest request (last retry).

Please try running your example with the following config:

await got('https://httpbin.org/delay/10', {
  timeout: { request: 1000 },
  retry: { limit: 0 }
});

You'll see that the execution time is pretty close to 1 sec.

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

No branches or pull requests

2 participants