4

When attempting to do a mvn grails:run-app on my project, I get the JVM_Bind error that 8080 is already in use. I've been running this project with no problems up until an Eclipse crash in the middle of running it. I've rebooted my machine twice and it doesn't clear this up. Netstat (netstat -ano) shows nothing on 8080. My tomcat is on 8088, and if I reconfigure it to run on 8080, it works fine, so that port is not in use. It is only maven and/or grails that has this error. Any ideas how I can clear this up?

$ netstat -ano

Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       752
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:623            0.0.0.0:0              LISTENING       7056
  TCP    0.0.0.0:1025           0.0.0.0:0              LISTENING       832
  TCP    0.0.0.0:1026           0.0.0.0:0              LISTENING       960
  TCP    0.0.0.0:1027           0.0.0.0:0              LISTENING       904
  TCP    0.0.0.0:1028           0.0.0.0:0              LISTENING       1128
  TCP    0.0.0.0:1033           0.0.0.0:0              LISTENING       888
  TCP    0.0.0.0:1034           0.0.0.0:0              LISTENING       5548
  TCP    0.0.0.0:2701           0.0.0.0:0              LISTENING       4788
  TCP    0.0.0.0:3306           0.0.0.0:0              LISTENING       1688
  TCP    0.0.0.0:3389           0.0.0.0:0              LISTENING       1452
  TCP    0.0.0.0:4369           0.0.0.0:0              LISTENING       3644
  TCP    0.0.0.0:5357           0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:5432           0.0.0.0:0              LISTENING       3604
  TCP    0.0.0.0:5672           0.0.0.0:0              LISTENING       3544
  TCP    0.0.0.0:8081           0.0.0.0:0              LISTENING       2928
  TCP    0.0.0.0:15672          0.0.0.0:0              LISTENING       3544
  TCP    0.0.0.0:16992          0.0.0.0:0              LISTENING       7056
  TCP    0.0.0.0:25672          0.0.0.0:0              LISTENING       3544
  TCP    10.0.0.252:139         0.0.0.0:0              LISTENING       4
  TCP    10.0.0.252:1060        74.125.22.188:5228     ESTABLISHED     7144
  TCP    10.0.0.252:1062        168.159.224.143:443    ESTABLISHED     6316
  TCP    10.0.0.252:55861       208.43.253.206:443     ESTABLISHED     7136
  TCP    10.0.0.252:57299       141.101.112.192:443    CLOSE_WAIT      8160
  TCP    10.0.0.252:57300       141.101.112.192:443    CLOSE_WAIT      8160
  TCP    10.0.0.252:57301       141.101.112.192:443    CLOSE_WAIT      8160
  TCP    10.0.0.252:57385       23.196.34.134:443      ESTABLISHED     7144
  TCP    10.0.0.252:57430       208.43.253.206:443     CLOSE_WAIT      7136
  TCP    10.0.0.252:57435       173.194.121.0:80       ESTABLISHED     7144
  TCP    10.0.0.252:57442       173.194.121.14:443     ESTABLISHED     7144
  TCP    10.0.0.252:57447       64.86.202.11:80        ESTABLISHED     7144
  TCP    10.0.0.252:57456       168.159.218.174:443    ESTABLISHED     6316
  TCP    10.0.0.252:57462       190.93.244.58:80       ESTABLISHED     7144
  TCP    10.0.0.252:57463       74.125.228.217:80      TIME_WAIT       0
  TCP    10.0.0.252:57470       23.196.2.197:80        ESTABLISHED     7144
  TCP    127.0.0.1:1029         0.0.0.0:0              LISTENING       2028
  TCP    127.0.0.1:1030         127.0.0.1:4369         ESTABLISHED     3544
  TCP    127.0.0.1:1035         127.0.0.1:62522        ESTABLISHED     7416
  TCP    127.0.0.1:1036         0.0.0.0:0              LISTENING       7136
  TCP    127.0.0.1:1164         0.0.0.0:0              LISTENING       996
  TCP    127.0.0.1:1165         0.0.0.0:0              LISTENING       7056
  TCP    127.0.0.1:2559         0.0.0.0:0              LISTENING       7060
  TCP    127.0.0.1:4369         127.0.0.1:1030         ESTABLISHED     3644
  TCP    127.0.0.1:55018        0.0.0.0:0              LISTENING       3112
  TCP    127.0.0.1:62522        0.0.0.0:0              LISTENING       1348
  TCP    127.0.0.1:62522        127.0.0.1:1035         ESTABLISHED     1348
  TCP    [::]:80                [::]:0                 LISTENING       4
  TCP    [::]:135               [::]:0                 LISTENING       752
  TCP    [::]:445               [::]:0                 LISTENING       4
  TCP    [::]:623               [::]:0                 LISTENING       7056
  TCP    [::]:1025              [::]:0                 LISTENING       832
  TCP    [::]:1026              [::]:0                 LISTENING       960
  TCP    [::]:1027              [::]:0                 LISTENING       904
  TCP    [::]:1028              [::]:0                 LISTENING       1128
  TCP    [::]:1033              [::]:0                 LISTENING       888
  TCP    [::]:1034              [::]:0                 LISTENING       5548
  TCP    [::]:2701              [::]:0                 LISTENING       4788
  TCP    [::]:3306              [::]:0                 LISTENING       1688
  TCP    [::]:3389              [::]:0                 LISTENING       1452
  TCP    [::]:5357              [::]:0                 LISTENING       4
  TCP    [::]:5432              [::]:0                 LISTENING       3604
  TCP    [::]:5672              [::]:0                 LISTENING       3544
  TCP    [::]:8081              [::]:0                 LISTENING       2928
  TCP    [::]:16992             [::]:0                 LISTENING       7056
  TCP    [::1]:1166             [::1]:1168             ESTABLISHED     7056
  TCP    [::1]:1168             [::1]:1166             ESTABLISHED     7056
  UDP    0.0.0.0:123            *:*                                    1092
  UDP    0.0.0.0:500            *:*                                    1128
  UDP    0.0.0.0:3702           *:*                                    1092
  UDP    0.0.0.0:3702           *:*                                    4152
  UDP    0.0.0.0:3702           *:*                                    1092
  UDP    0.0.0.0:3702           *:*                                    4152
  UDP    0.0.0.0:4500           *:*                                    1128
  UDP    0.0.0.0:5355           *:*                                    1452
  UDP    0.0.0.0:8082           *:*                                    2928
  UDP    0.0.0.0:54654          *:*                                    4152
  UDP    0.0.0.0:54960          *:*                                    7144
  UDP    0.0.0.0:59195          *:*                                    1092
  UDP    0.0.0.0:63291          *:*                                    1092
  UDP    10.0.0.252:137         *:*                                    4
  UDP    10.0.0.252:138         *:*                                    4
  UDP    127.0.0.1:48000        *:*                                    7060
  UDP    127.0.0.1:49153        *:*                                    3604
  UDP    127.0.0.1:61532        *:*                                    6316
  UDP    [::]:123               *:*                                    1092
  UDP    [::]:500               *:*                                    1128
  UDP    [::]:3702              *:*                                    4152
  UDP    [::]:3702              *:*                                    4152
  UDP    [::]:3702              *:*                                    1092
  UDP    [::]:3702              *:*                                    1092
  UDP    [::]:4500              *:*                                    1128
  UDP    [::]:8082              *:*                                    2928
  UDP    [::]:54655             *:*                                    4152
  UDP    [::]:59196             *:*                                    1092
  UDP    [::]:63292             *:*                                    1092
JenVander
  • 325
  • 2
  • 11
  • Did you try cleaning the project via eclipse and running again? Have you tried running it straight from the console (pardon my ignorance, I'm not sure what mvn grails:run-app is exactly, which I assume means you are running it through another program. My guess is it's something to do with eclipse is causing the issue if you've rebooted and still have the error.) I would also double check and kill any java process you might have running if all that doesn't work (overkill is still dead right?). – Ted Delezene Jul 02 '15 at 19:44
  • Yes, did clean package, and ran from command line too, same result. No java processes -- I've rebooted twice, but I do ps -eaf each time to be sure (and I check the task manager too). It is a head-scratcher, this one. I'm wondering if the JDK got corrupt, so I'm going to try a reinstall next. Any other ideas you might have I'm game to try :) – JenVander Jul 02 '15 at 20:49
  • It would be nice if you were to edit your question to include the actual netstat command that you're running and the output that it produces, to verify you're interpreting it correctly. Taking your description at face value, on unix my next step would be to produce the error while strace'ing the process to see what actual system call is triggering the JVM error. On windows, these look promising for that kind of troubleshooting: http://stackoverflow.com/questions/3847745/systrace-for-windows – Kenster Jul 02 '15 at 21:28
  • Sure thing -- done. Though I have a high level of confidence that the IP address issue was the problem and that the error message was simply poor and misleading. Making the edit for posterity as it may help a future visitor. – JenVander Jul 02 '15 at 21:43

2 Answers2

2

The problem was not an already-bound port in use, it was an invalid IP address. I had re-connected to my VPN and DHCP had given me a new IP address. My binding in the grails application was to the old IP address. Changing to the new, valid IP address fixed the problem. To verify this, I modified the grails IP binding to a known invalid IP address and it reproduced the problem. This is a case of a bad or misleading error message. Normally this error is caused by a process hanging on to the port, but in my situation, as my netstat output demonstrated, that was not the problem. So if anyone else has this problem, check on the ports and check your IP address.

JenVander
  • 325
  • 2
  • 11
2

A Bind error is caused because a process is still registered using the respective port. This also includes zombie processes that haven't died and have been lost in the either.

A reboot will clean this out, but as I am apposed to the reboot solution, you can use the netstat (same command on windows, linux & mac) command to find out the zombie process.

What you need is the netstat command, you will need to look at the documentation on each operating system (try netstat -?), but usually what you're looking for is something like netstat -a, which will list all ports being used.

What we are most interested in the ones that are in a state of LISTENING, which means that something has bound that port for listening, which will include your 8080 port.

Again, you will need to have a look at the command options as each OS has different options that will allow you to display the PID (process ID). You can then use your 'Task Manager'/'Activity Monitor'/'top' app to then to match the PID with your running application, and kill that application.

In Mac you will need to also use the below command for getting the PID.

lsof -i -U -P | grep "LISTEN"

Once you have killed that process, your port will then be available and you can then run your program without the JVM_Bind issue.

P.S. One think to note also; Java won't bind ports that are under something like 1200, unless you're running as Administrator/root user. But your 8080 should be fine.

Guy Park
  • 959
  • 12
  • 25
  • Though this is a good standard response, and the more usual root-cause, it was not the root-cause in this instance. There were no processes bound to the port -- it appears to have been a bad IP address combined with a misleading error message. – JenVander Jul 02 '15 at 22:13