Otiel
Otiel

Reputation: 18743

Close TCP connection when owner process is already killed

I have a Windows service that - when it starts - opens some WCF services to listen on the 8000 port. It happens that this service crashes sometimes. When it does, the TCP connection is not released, thus causing my service to throw an exception if I try to start it again:

AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:8000

Some observations:


The only way I found to release the connection is to restart the server (which is not convenient in a production environment as you can guess). Waiting does not help, the TCP connection is never released.

How can I close the connection without restarting the Windows server?


PS: found some questions extremely similar to mine.

Upvotes: 8

Views: 4390

Answers (2)

David P Simons
David P Simons

Reputation: 167

I had the same problem and eventually figured out that the port was being held open by a child process that had been sublaunched by my process. Not sure why none of the system tools could tell me that. Ending the child process frees up the port.

Upvotes: 2

Eitan Revach
Eitan Revach

Reputation: 11

I suggest you trying socket.ExclusiveAddressUse=false; Althought isn't usually intended to solve this kind of probelms.

Another work-around - locate the other service process and kill it manually in your very first code lines.

Upvotes: 0

Related Questions