question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ECONNRESET when handling requests asynchronously

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
pietermeescommented, Mar 18, 2018

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

0reactions
santoshrajancommented, Mar 19, 2018

@pietermees Good job! Been after this for a few days with no luck!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found