I have a problem with a TCP socket getting "broken pipe" after a couple of hours of disuse. The server is sending packets every 300ms to the client but the client sends packets back on the socket very rarely sometimes days apart. The server to client part of the socket is still alive when the broken pipe is noticed after two consecutive packets from client to the server (this is expected behaviour when one half of the socket is closed). Neither server nor client notice the socket is closed until the client sends data.
Update: This is not entirely correct, the client spawns two sockets and one is not emptied leading to the problem - see answer.
How do I go about debugging this issue?
Does anyone have any idea why this would happen?
Some backstory: I re-implemented a socket server in Rust using std::net, the old implementation was Python3. The server works exactly the same, the clients are written in Python3. The server and clients both run locally on a fedora 27 Linux x86-64 machine. This problem is not present when running the python server, which should eliminate the operating system or hardware as the cause - right?