ECONNRESET when handling requests asynchronously
See original GitHub issueI’m seeing an issue where if
- the request handler is asynchronous (in that it doesn’t respond to the request in the same event loop tick)
- the server receives new requests while a previous one is still being handled
I will randomly get an ECONNRESET
error on the client without any finish
, end
, close
or error
events on the server req.socket
object.
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
node.js - ECONNRESET when using async to scrape archive
I'm using the node.js async.js library to scrape the page, but I am having a heck of a time with always getting an...
Read more >Errors | Node.js v19.3.0 Documentation
ECONNRESET (Connection reset by peer): A connection was forcibly closed by a peer. This normally results from a loss of the connection on...
Read more >read econnreset - You.com | The search engine you control.
"ECONNRESET" usually happens when another end of the TCP connections closes its end due to any protocol-related errors and since no one is...
Read more >Synchronous and asynchronous requests - Web APIs | MDN
Synchronous requests block the execution of code which causes "freezing" on the screen and an unresponsive user experience. Asynchronous request.
Read more >Nodejs HTTPS ECONNRESET ~ Ozkary
Since there is not an explicit socket connection sending data to the server, the request will just hang, and the server will eventually...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
With some further digging I think I found the origin of the issue.
TLDR: the server runs out of backlog for new connections
It’s indeed possible to reproduce the issue with Node’s native
http
module, but only with much larger request counts.The reason is the
backlog
parameter toserver.listen
. Node uses511
by default, although this is further limited by the OS’sSOMAXCONN
setting. On my Mac that defaults to128
. If I setSOMAXCONN=1024
I can get rid of the error.The reason why the problem happens much sooner with
turbo-http
is thatturbo-net
sets the backlog size to a fixed5
. This means that only 5 connections can be queued up to be accepted by the server before new connections get rejected. By sending a lot of simultaneous requests, it’s easy to cross that limit.Here’s the line in
turbo-net
causing this (note the TODO about researching backlog): https://github.com/mafintosh/turbo-net/blob/master/src/turbo_net.c#L190@pietermees Good job! Been after this for a few days with no luck!