Background
I have a .net 4.0 WCF application that listens on net.tcp port 667. (Windows 7 machine)
At some point the application exits ungracefully (the user kills the process, for example).
Now a strange thing happens: The port remains open. When the user re-starts the application, it fails to listen on that port since it's already in use.
The strange thing is that even though the owning process was killed, the OS does not close the port, not even after several hours.
Here are some observations:
- On TcpView the process is
<non-existent>
, the PID belongs to the old (killed) process, and state isLISTENING
. Local address is my machine and there are bothIPV4
andIPV6
listeners on that port. - "Close Connection" and "End Process" operations on TcpView have no effect on that port.
- Process Explorer does not display the old (killed) process. I tried to search-handle for the PID or the port but found nothing.
- When running
netstat -a -b -n -o
the executable involved is displayed asSystem
and local address is0.0.0.0
. Other info is the same as TcpView.
The only way I found to close that port was a system reboot...
Questions
- Is there a way to configure the WCF net.tcp Service Host listener to avoid lingering after the process exists ungracefully?
- Is there a way to programatically close that port? If there is, my application could first close that port before trying to listen to it.
- Is there a utility that could close such "daemon" ports? (since TcpView cannot do that)
- Is this an OS bug? Shouldn't the OS keep track of such "daemon" listeners and close them once the process exists?