got: Uncaught 'TimeoutError' exception
Describe the bug
- Node.js version: 12.x.x (it’s electron 5.0.7)
- OS & version: Windows 8.1 & 10 (both 64-bit)
I’m sporadically getting uncaught ‘TimeoutError’ exception that is hard to reproduce in controlled manner. Happens in production where the app is making a lot of requests and running on devices with intermitted mobile internet connection.
Actual behavior
Uncaught exception:
TimeoutError: Timeout awaiting 'request' for 10000ms
at timeoutHandler (C:\myproject\node_modules\got\dist\source\core\utils\timed-out.js:36:25)
Expected behavior
There shouldn’t be any uncaught exception.
Code to reproduce
process.on('uncaughtException', function(err) {
console.log('UNHANDLED ERROR:', err.stack);
});
async function getResponse() {
try {
return await got('https://someurl.com/', { timeout: 10000, retry: 0 }).text();
} catch (err) {
console.log('HANDLED ERROR:', err.stack);
}
}
When there’s some timeout error, most of the time it’s handled properly:
HANDLED ERROR: RequestError: Timeout awaiting 'request' for 10000ms
at ClientRequest.<anonymous> (C:\myproject\node_modules\got\dist\source\core\index.js:934:25)
at Object.onceWrapper (events.js:282:20)
at ClientRequest.emit (events.js:199:15)
at ClientRequest.EventEmitter.emit (domain.js:469:20)
at ClientRequest.origin.emit (C:\myproject\node_modules\@szmarczak\http-timer\dist\source\index.js:39:20)
at Socket.socketErrorListener (_http_client.js:401:9)
at Socket.emit (events.js:194:13)
at Socket.EventEmitter.emit (domain.js:469:20)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:81:17)
at timeoutHandler (C:\myproject\node_modules\got\dist\source\core\utils\timed-out.js:36:25)
But in some rare occasions I get this unhandled exception:
UNHANDLED ERROR: TimeoutError: Timeout awaiting 'request' for 10000ms
at timeoutHandler (C:\myproject\node_modules\got\dist\source\core\utils\timed-out.js:36:25)
Checklist
- I have read the documentation.
- I have tried my code with the latest version of Node.js and Got.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 21 (10 by maintainers)
Looks like the patch is only targeting node v14 or lower while I experimented with the error on node v15 🤔
but let’s see. Glad to be able to test it in the next got version and to be able to report feedback
Fixed in 31d80efaabdc6b0fc9ae5195ce8db623aceb9c13
Let’s go with
applyDestroyPatch
.Electron 5.0.7 is using Node.js 12.0.0.
I’m also updating to latest Electron so I’ll see if the problem persists.