turbo-http: ECONNRESET when handling requests asynchronously
I’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.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (15 by maintainers)
Commits related to this issue
- Set default backlog size to 511 Match Node's default backlog of 511 sockets (see https://nodejs.org/dist/latest-v9.x/docs/api/net.html#net_server_listen) This helps address https://github.com/mafint... — committed to pietermees/turbo-net by pietermees 6 years ago
- Set default backlog size to 511 (#9) Match Node's default backlog of 511 sockets (see https://nodejs.org/dist/latest-v9.x/docs/api/net.html#net_server_listen) This helps address https://github.com/m... — committed to mafintosh/turbo-net by pietermees 6 years ago
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