Skip to content
Tech News
← Back to articles

The occasional ECONNRESET

read original get Network Troubleshooting Ethernet Adapter → more articles
Why This Matters

This article explores the intermittent ECONNRESET errors occurring between two local services communicating over TCP sockets, highlighting how large data transfers can trigger connection resets without clear errors. Understanding this behavior is crucial for developers optimizing networked applications and troubleshooting connection stability issues in the tech industry.

Key Takeaways

blog - git - desktop - contact

The occasional ECONNRESET (part 1/2)

Two services running on the same machine. One of them opens a listening TCP socket bound to localhost, the other one connects to that. They exchange data. Every now and then, the service that initiated the connection gets an ECONNRESET while reading data from the socket -- but no other errors show up in the logs, no crashes, nothing. What's going on?

Go on to part 2.

A reproducer in the "lab"

Let's start with the "server", i.e. the service that opens the listening socket.

The following program does just that: Create a new TCP socket, wait for connections, fork into a new process for each request. There's not much of a "request", though: The server simply dumps 600'000 x bytes to the client upon connection.

The number 600'000 bears some meaning: It needs to be large enough to trigger the behavior that I want to show. 600 bytes, for example, probably won't work.

server.c

Now on to the client: It connects to port 8125 on localhost where our server is waiting, and then it calls recv() until EOF or error. We'll get to the --spam flag in a second.

... continue reading