How can I identify which process is using port 18780 on Windows? - windows

I have an internal web application listening on all IPs on port 18780. When I try to start the application on a new Windows VM it throws this exception:
System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:18780
After rebooting the machine the application starts just fine, but I'd like to avoid having to reboot all of my new QA environments before I can use them.
IANA reports that nothing well-known uses port 18780.
The last time this happened I tried to identify what process was running on that port:
Running Get-Process -Id (Get-NetTCPConnection -LocalPort 18780).OwningProcess returned Cannot find a process with the process identifier 7188. Powershell is running under a local admin account.
So what's happening here? It looks like there's something using that port, it's got a process Id, but I'm unable to get the details of it. Running this powershell command a second time reports that there's nothing listening that port. Does the act of observation change Windows processes?
What further steps can I take to find out more about Schrödinger's process?

Caught this happening again.
Turns out that my application had spawned three child processes, and those were still running. Windows apparently doesn't release a TCP port until the owning process record is cleaned up, and child processes maintain this record. Even though the parent process was stopped, and showed in TCPViewer as <non-existent>, the port was still unavailable.
This is also described here: https://serverfault.com/questions/181015/how-do-you-free-up-a-port-being-held-open-by-dead-process
I used wmic process where (ParentProcessId=7188) get Caption,ProcessId to identify which child processes to kill, and that did the trick. Windows released the port straight away.

try following in powershell:
netstat -ano | findstr :<port>
this will give you the details about the process id
then use following to kill the process:
taskkill /PID <processid> /F

Related

Terminating port of spring boot application in Eclipse

Terminated by clicking on Red Icon in console tab but when I rerun it is saying port is already in use.
I terminated port using Taskkill command in command prompt. Any suggestions on terminating it from Eclipse would be helpful instead of command prompt
Usually terminating application from Eclipse helps. Sometimes, though, it doesn't help. In such cases, I have to restart the eclipse. Unfortunately, I don't have any better solution. There might be something wrong with your application, if this issue happens too often for you. Eclipse usually tries to "gracefully" shut down the application and release resources, before shutting down the server. Maybe during this time the application "hangs" and doesn't respond. There could be many reasons for that. One of them: your application doesn't close file resources correctly, with try... finally, and so on.
To summarise: In 95% of the cases, shutting down the server from eclipse works. If it doesn't, then you have to restart the eclipse, or maybe even kill the process from the command-line. If it happens too often, let's say in 50% of the cases, then there is something wrong with your application.
Open Eclipse
Go to Servers panel
Right click on Tomcat Server select Open, Overview window will appear.
Open the Portstab. You will get the following:
Tomcat adminport
HTTP/1.1
AJP/1.3
I changed the port number of HTTP/1.1 (i.e. to 8081)
You might have to also change the port of Tomcat adminport (i.e. to 8006) and of AJP/1.3 (i.e. to 8010).
Access your app in the browser at http://localhost:8081/...
I found the best way to stop spring from holding the port was to write a script that looks for the process holding the port and auto kill it. Then attach that script to an external tool job in eclipse. I adapted a powershell script I found. Called it kill-port.ps1 and is located in base of the report where I had the issue.
param ($port)
$foundProcesses = netstat -ano | findstr :$port
$activePortPattern = ":$port\s.+LISTENING\s+\d+$"
$pidNumberPattern = "\d+$"
IF ($foundProcesses | Select-String -Pattern $activePortPattern -Quiet) {
$matches = $foundProcesses | Select-String -Pattern $activePortPattern
$firstMatch = $matches.Matches.Get(0).Value
$pidNumber = [regex]::match($firstMatch, $pidNumberPattern).Value
taskkill /pid $pidNumber /f
}
Then set up an external tool configuration
Location: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe
Argument: ${workspace_loc:/workspacename/kill-port.ps1} 8080
Now I just run the kill command after each test where I know it leaves the port bond to a process. Not the most elegant but easier then running a few commands in a shell. This is windows specific but I am sure the same type script can be created for Unix.

Windows 10 Kill EDB Postgres 8080 server

I want to kill and remove the software that uses the 8080 port that EDB Postgres localhost server so I can use the port for Jenkins.
Using tasklist it tells me the port which is processing, fine for kill the process, but where can I delete uninstall the software.
Just find the server named "PEM HTTPD" and turn it off.Also you can change its start mode to manual.
tasklist is good but you can also use netstat -ano to find the port if you didn't find the process but in taskmanager in windows 10 there is a services tab with a PID column. Just click the column and find the PID. Then right click it and hit properties to find the path of the software. Kill the process and remove the software. Restart and see if it works.

On Windows, is there a way to tie a running service to the pid of a process that was spawned by nssm?

(updated for requested clarification)
I need to associate a running service to a particular jvm / java command with args. To complicate things, the application uses nssm (non-sucking service manager) to execute a .bat. Inside the .bat are the args that end up running with the java process.
There is a running service, let's call it service1. This service is listed in the list of services, you can stop and restart it, and that usually works.
Sometimes, service1 restarts, but the underlying jvm stays running, and causes a problem when the next one is created because it cannot bind to the same listening port.
So you find out the path for the service with this command:
Get-CimInstance win32_service |
where-object Name -eq "service1" |
select pathname
pathname
\nssm\nssm.exe
So far, so good.
(to be continued)
Has anyone faced this scenario before? Is there some way when nssm starts a process that it keeps track of what is executed in child processes?

Restarting Hudson on Windows

I've been having an issue with Hudson on windows.
Whenever I update Hudson or a plugin I get the option to restart when no jobs are running.
If I click this button Hudson hangs and doesn't restart. I've tried restarting the Hudson service but this doesn't help, so end up having to reboot the box to bring Hudson back online.
I've just updated to the most recent version, but didn't click the restart button and it's now vanished.
Is there a correct way to restart Hudson on windows?
Cheers
Tom
I have a this problem once in a while too. For some reason the Hudson server does not shut down completely and the server that starts up, can not use the port. To fix that problem, I run `netstat -n -o'. This way I can find out the process ID that holds the port and kill that app through taskmanager. Now I can restart the service and Hudson comes up fine.
For the last few weeks I had a similar problem. The description says, that it restarts the app, when no processes are running. I missed out on one job that was hold in the build queue and because of a faulty configuration never actually build, therefore preventing Hudson from restarting.
After all of your jobs are finished and your server does not restart. Just visit the restart page again http://server:port/restart and try to restart again. If that doesn't work stop the service and start it again.
UPDATE:
Since I grew tired of physically logging into the Hudson/Jenkins server, I now use following commands to run the kill remotely. These commands assume that you run the service with a dedicated user (e.g. JenkinsUser). If another process running with the same credentials than the service does and might start java.exe, you need to run the netstat which needs to be executed locally on the Jenkins server or by using rexec (this was not an option for me).
:: get the pid of jenkins java.exe
tasklist /S %JENKINSSERVER% /FI "IMAGENAME eq java.exe" /FI "USERNAME eq %DOMAIN\USERNAME%"
:: terminate process use pid from previous command (instead of 1234)
taskkill /S %JENKINSSERVER% /F /T /PID 1234
:: stop the Jenkins service (just in case the service is hanging)
sc \\%JENKINSSERVER% stop Jenkins
:: start the Jenkins service again
sc \\%JENKINSSERVER% start Jenkins
If I have to much time, I might create a script out of it.
If the Slave node has the slave.jar used as a windows service, that service is defined as "Automatic".
It means it will try to contact the master periodically if the connection has been severed.
You shouldn't click on anything on the server side (in the Node definition) to restart said Node: it should be back online automatically.
If you've installed Jenkins on a TomCat server, one alternative solution is to simply restart your Apache TomCat service.

How to kill a glassfish server in Windows?

I tried to start a glassfishv3 server in my windows XP system with the command "asadmin start-domain". The start failed due to a timeout. When I try to start again I get an error saying that the port 4848 is allready in use by another process. When I try to stop the server with "asadmin stop-domain" I get the error that it is not running.
Any idea how to solve this deadlock? I cannot find a Windows process with the name glassfish or asadmin to kill.
The process will be java.exe
You can use one of the sysinternals tools, like tcpview.exe for example to see which program is actually using that port.
Adding to Alexis' answer,
jps -v
will show you more about the java processes. Note the pid. You must have configured your path correctly for this to work.
Then do
taskkill /pid <pid>
You can also use jps to list all the Java processes on you machine. The GlassFish server main class is called ASMain

Resources