49
15
I'm developing an app that listens on port 3000. Apparently there's an instance of it still listening to the port because whenever I start it, it can't create a listener (C#, TcpListener, but that's irrelevant) because the port is already taken.
Now, the app doesn't exist in the Task Manager, so I tried to find its PID and kill it, which led to this interesting result:
C:\Users\username>netstat -o -n -a | findstr 0.0:3000
TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 3116
C:\Users\username>taskkill /F /PID 3116
ERROR: The process "3116" not found.
I haven't seen this behaviour before and figured it was interesting enough to see if anyone has a solution.
UPDATE: I started up Process Explorer and did a search for 3000 and found this:
<Non-existent Process>(3000): 5552
I right clicked on it and chose "Close Handle". It's no longer in Process Explorer, but still shows up in netstat and still stops the app from starting the listener.
UPDATE 2: Found TCPView for Windows which show the process as "<non-existent>"
. Like with CurrPorts, nothing happens when I try to close the connection in this tool.
Add the
/T
option (taskkill /F /T /PID 17888
) to also kill children and the error changes in an interesting way:ERROR The process with PID 17888 (child process of PID 17880) could not be terminated. Reason: There is no running instance of the task.
In this case 17888 is running but 17880 is not. So I have an orphaned process locked by a dead parent. – Jesse Chisholm – 2015-06-07T15:07:28.8571With current version of TCPView 3.05 "Close connection" from context menu of <non-exsitent> process successfully closed the connection in my case and freed the port. – Ventzy Kunev – 2019-04-23T12:12:04.283
1
See also https://serverfault.com/questions/181015/how-do-you-free-up-a-port-being-held-open-by-dead-process
– rogerdpack – 2019-04-29T22:14:50.750a bit of curing the disease by killing the patient, but does it stop if you restart the computer? – Xantec – 2010-11-26T15:30:54.473
2In fact, logging out and back in again was enough, but I've now managed to reproduce it so I'd still like to find a better solution... – Srekel – 2010-11-26T16:09:10.947
Check if any of the programs listed here help
– Sathyajith Bhat – 2010-11-26T16:38:47.340Sathya, thanks but they didn't. More about files than ports I'm afraid. – Srekel – 2010-11-26T17:30:54.417
@Srekel ok.. I've posted an answer, that might help you. – Sathyajith Bhat – 2010-11-27T01:44:46.407
Perhaps you should look into exactly how you implement your listening on the port. Maybe it's a bug in your implementation or in C#'s handling of it. (Memory management perhaps?) – Moshe – 2010-11-29T15:54:57.613
@Moshe: See my answer. – harrymc – 2010-11-29T20:29:55.703
@srekel any updates ? – Sathyajith Bhat – 2010-12-03T02:04:53.187
I have the exact same problem...damn no answer here! – mmmmmmmm – 2013-04-15T10:07:15.557
Sorry, I don't think I ever found a solution to the problem and have since left the company. :/ – Srekel – 2013-04-29T14:32:03.353