Got: Got doesn't throw a timeout error when passing an agent

Created on 6 Aug 2020  路  12Comments  路  Source: sindresorhus/got

Describe the bug

  • Node.js version: v13.14.0
  • OS & version: osx 10.15.6


Timeout option not working with proxy (using tunnel as proxy)

Code to reproduce

got('https://example.com', {
    timeout: 50,
    agent: {
        https: tunnel.httpsOverHttp({
             proxy: {
                 host: '175.44.108.137',
                 port: 9999
            }
        })
    }
})

set agent https to tunnel.httpsOverHttp, got timeout is invalid!!!

bug external nodejs bug

Most helpful comment

A workaround is to utilise the cancel method with a setTimeout. It won't give you a TimeoutError, but it does the job and throw you an error.

const request = got(options);
const timeout = setTimeout(() => request.cancel(), this.timeout);

const response = await request;
clearTimeout(timeout);

All 12 comments

timeout is milliseconds, not seconds.

I know timeout is milliseconds!
My question is Timeout option not working with proxy (using tunnel as proxy)

Timeout option is not work, when i add 'proxy agent' option
if i remove 'proxy agent', timeout is work.
but I need them both, and how could i figure it out?

Is there any solution to this bug or an alternative way to timeout a request with a proxy? If not, is a fix planned soon?

Running into this issue as well, if anyone knows of a workaround it would be greatly appreciated

A workaround is to utilise the cancel method with a setTimeout. It won't give you a TimeoutError, but it does the job and throw you an error.

const request = got(options);
const timeout = setTimeout(() => request.cancel(), this.timeout);

const response = await request;
clearTimeout(timeout);

The same problem.
Snipaste_2020-11-08_14-54-55

A workaround is to utilise the cancel method with a setTimeout. It won't give you a TimeoutError, but it does the job and throw you an error.

const request = got(options);
const timeout = setTimeout(() => request.cancel(), this.timeout);

const response = await request;
clearTimeout(timeout);

got.cancel is not a function

It's request.cancel, not got.cancel. ;)

Same problem here, what is exactly the reason for that error? the 'request' timeout should start even before trying to connect to the proxy right? why is not working?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

darksabrefr picture darksabrefr  路  3Comments

framerate picture framerate  路  4Comments

lukechu10 picture lukechu10  路  3Comments

quocnguyen picture quocnguyen  路  4Comments

khizarsonu picture khizarsonu  路  3Comments