I have a script that uses IO::Socket::INET to establish a TCP server
my $socket = new IO::Socket::INET (
LocalHost => '0.0.0.0',
LocalPort => '10010',
Proto => 'tcp',
Listen => 5,
);
If my script crashes or is stopped by the user before it reaches the closure of the server socket, then the next time the script is run it cannot bind to the port as there is still a process listening on the to port
Except from the results netstat -anobp tcp
TCP 0.0.0.0:10010 0.0.0.0:0 LISTENING 22628
[System]
Yes I am using Windows.
A task kill request:
taskkill /f /PID 22628
fails with:
ERROR: The process "22628" not found.
The only way to get around this is to reboot, or increment the listening port. Since I am not a real software developer and can write great code first time that doesn't crash, then I run into this problem a lot.
Also worth noting that this happens only once a client has connected to the server.
Is there a way to stop this from happening (no orphan listen process) or a way of getting rid of orphan?