How do I kill all sockets when my app dies

Hi I have a tokio based tcp app. When I kill and try to restart my app for some time I keep getting address in use error and although lsof does not list any active processes listenning to the port sudo netstat -tanl | grep <port> shows me a bunch of sockets left from the dead process.
How do I completely clean those up when my process dies

What kind of sockets does your program use? Are you perhaps using explicitly bound client connections? Generally, "address in use" errors are avoided by setting SO_REUSEADDR on server sockets (TcpListener::bind() does this automatically), or using ephemeral ports for clients (as in TcpStream::connect()).

You can't, they must remain in TIME_WAIT for twice the maximum segment lifetime according to the TCP specification.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.