turbo-http: ECONNRESET when handling requests asynchronously

I’m seeing an issue where if

  1. the request handler is asynchronous (in that it doesn’t respond to the request in the same event loop tick)
  2. 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

Most upvoted 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 to server.listen. Node uses 511 by default, although this is further limited by the OS’s SOMAXCONN setting. On my Mac that defaults to 128. If I set SOMAXCONN=1024 I can get rid of the error.

The reason why the problem happens much sooner with turbo-http is that turbo-net sets the backlog size to a fixed 5. 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