got: Intermittent uncaught errors
With got version 9.2.2, I’m seeing timed-out
crash occasionally with an unhandled error
event. I’m using the promise API, not the stream-based one, so I expect this event to always be turned into a promise rejection.
TimeoutError: Timeout awaiting 'response' for 2000ms
at Immediate.timeoutHandler (/node_modules/got/source/timed-out.js:39:25)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 34
Looks like it’s because the
socket
timeout handler doesn’t calladdTimeout()
? ThetimeoutHandler
that it calls doesn’t guarantee that it will emit anerror
at most once.Yes, it’s the full stack trace. As far as I know, that’s all you get with errors thrown from timers, at least by default?
I think this is related to the
retry
option. I can reproduce it by passing in a hostname that has never been looked up before, setting all timeouts to 1 ms, and settingretry
to 1:With got v9.3.1 on Node v8.12.0, that logs:
I get the same behavior with Node 10 and 11.
Strange that it times out on
connect
as well. That would mean that the DNS lookup happened, failed (the hostname is invalid), and the timeout logic for the TCP socket still kicked in. Perhaps that’s part of the problem?I’ve also added longjohn to obtain the async stack trace. That gives me:
In
timed-out.js
, shouldn’t you be checking the first argument of thelookup
handler? It’s anError
if the lookup fails, so in that case, you’ll never get theconnect
event. But then, that should still reject the promise rather than producing an uncaught error.I believe I’m seeing something similar. It’s also intermittent. Trace looks like this
EventEmitter
that emits anerror
event and the argument of that is theTimeoutError
that gets logged.