sindresorhus / got

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

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

Closed lounsbrough closed 5 years ago

lounsbrough commented 5 years ago

Describe the bug

The timeout option does not seem to work when using a proxy. I'm using tunnel per the examples in the README.

Actual behavior

timeout option set to 10000 milliseconds. Request via proxy takes > 30 seconds to timeout.

Expected behavior

Request should timeout after the specified number of milliseconds.

Code to reproduce

const response = await got(url, {
    agent: tunnel.httpsOverHttp({
        proxy: {
            host: proxy.host,
            port: proxy.port,
            proxyAuth: `${proxy.username}:${proxy.password}`,
            headers: getRequestHeaders()
        }
    }),
    headers: getRequestHeaders(),
    timeout: 10000
});

Checklist

szmarczak commented 5 years ago

Can you set the retry option to 0 and try again?

lounsbrough commented 5 years ago

With timeout set to 0, the connections fail almost instantly.

szmarczak commented 5 years ago

Is it a Timeout Error?

lounsbrough commented 5 years ago

Yes.

TimeoutError: Timeout awaiting 'request' for 0ms
    at ClientRequest.request.once.error (E:\nodejs\determine-max-available-ship-quantity\node_modules\got\source\request-as-event-emitter.js:163:14)
    at Object.onceWrapper (events.js:273:13)
    at ClientRequest.emit (events.js:187:15)
    at ClientRequest.origin.emit.args [as emit] (E:\nodejs\determine-max-available-ship-quantity\node_modules\@szmarczak\http-timer\source\index.js:36:11)
    at Immediate.timeoutHandler (E:\nodejs\determine-max-available-ship-quantity\node_modules\got\source\utils\timed-out.js:63:11)
    at processImmediate (timers.js:634:17)
szmarczak commented 5 years ago

Try setting timeout to 1000 and retry to 0. Does it fail?

lounsbrough commented 5 years ago

With retries set to 0, it also fails immediately.

lounsbrough commented 5 years ago

I've found a workaround which is to reject the Promise with my own timeout. I'm going to close this issue and if it becomes a problem for me again I'll upload example code of the failure. Thanks!

shikar commented 4 years ago

Describe the bug

  • Node.js version: 11.0.0
  • OS & version: Windows 10 Pro

The timeout option does not seem to work when using a proxy. I'm using tunnel per the examples in the README.

Actual behavior

timeout option set to 10000 milliseconds. Request via proxy takes > 30 seconds to timeout.

Expected behavior

Request should timeout after the specified number of milliseconds.

Code to reproduce

const response = await got(url, {
    agent: tunnel.httpsOverHttp({
        proxy: {
            host: proxy.host,
            port: proxy.port,
            proxyAuth: `${proxy.username}:${proxy.password}`,
            headers: getRequestHeaders()
        }
    }),
    headers: getRequestHeaders(),
    timeout: 10000
});

Checklist

  • [x] I have read the documentation.
  • [x] I have tried my code with the latest version of Node.js and Got.

How to solve it?

szmarczak commented 4 years ago

@shikar If you're having a similar issue to this one, please open a new issue.