I have a systemd service unit that starts a tcp server on a specific port on the host machine.

but on restart the port cotinue to run and if I restart the service I get an error address already in use.

on digging more I found the port of tcp server is still open because service failed to start but if we stop the service the open tcp port closes.

  • After an ungraceful shutdown, a tcp socket can remain in the in-use state for typically 2 minutes. can this be your problem? – Klaas van Aarsen Nov 23 '19 at 22:16
  • It it is, then netstat will show that the socket state is TIME-WAIT. Is it? – Klaas van Aarsen Nov 23 '19 at 22:17
  • Possible duplicate of Kill TIME_WAIT sockets immediately? – Andy Dalton Nov 23 '19 at 22:18
  • That's a very old thread with actually very little information @AndyDalton. – Klaas van Aarsen Nov 23 '19 at 22:21
  • The linked thread does not help me. – Ciasto piekarz Nov 23 '19 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.