feross / simple-get

Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines
MIT License
401 stars 50 forks source link

timeout with HTTPS #47

Closed shakermm closed 5 years ago

shakermm commented 5 years ago

I noticed if the request url is https timeout doesn't work, see example below

const get = require('simple-get')

const opts = {
  url: 'http://example.com',
  timeout: 10
}

get(opts, function (err, res) {
  console.log('HTTP', err);
})
})
// result
// HTTP Error: Request timed out
//     at ClientRequest.req.on (/home/runner/node_modules/simple-get/index.js:67:8)
//     at ClientRequest.emit (events.js:180:13)
//     at Socket.emitRequestTimeout (_http_client.js:641:42)
//     at Object.onceWrapper (events.js:272:13)
//     at Socket.emit (events.js:180:13)
//     at Socket._onTimeout (net.js:396:8)
//     at ontimeout (timers.js:466:11)
//     at tryOnTimeout (timers.js:304:5)
//     at Timer.listOnTimeout (timers.js:267:5)

const opts2 = {
  url: 'https://example.com',
  timeout: 10
}

get(opts2, function (err, res) {
  console.log('HTTPS', err);
})
// result
//HTTPS null
bendrucker commented 5 years ago

Can't reproduce. Just ran this and got a socket timeout as expected:

require('simple-get')({url: 'https://google.com', timeout: 1}, console.log.bind(console))
shakermm commented 5 years ago

here is demo , am I missing something ? https://repl.it/@MikeShaker/simple-get-Timeout-demo

bendrucker commented 5 years ago

That website is super flaky for me, republished a simpler example here, still not reproducible:

https://runkit.com/bendrucker/5c50a6be8b22250011f20960

shakermm commented 5 years ago

Thank you, it has to be an issue with repl.it, even my example worked on runkit. Thanks again