4

When I execute netstat -tupan, one of the entries is the following:

tcp        0      0 :::1099  :::*         LISTEN      8778/java

However, I have removed all settings concerning RMI and JMX from the options passed to Java when it starts. My questions are:

  1. Is RMI actually still enabled? I can connect to the port using telnet.
  2. If not, why does Java still listen on the port?

Edit: I blocked the port using netcat: nc -l 1099. This prompted an error on the application startup, and it turns out that I have an MBean in the application which was automatically picked up by Spring on startup and registered.

JohnEye
  • 6,436
  • 4
  • 41
  • 67
  • Did you try to put your IP/Port in blackhole, just to make sure RMI is culprit – T-Bag Jun 05 '17 at 10:18
  • What's under 8778 PID? https://stackoverflow.com/questions/821837/how-to-get-the-command-line-args-passed-to-a-running-process-on-unix-linux-syste – jannis Jun 05 '17 at 10:18
  • @jannis: That's my Java application running within Tomcat. – JohnEye Jun 05 '17 at 11:14
  • @ShowStopper: How would that help me identify the cause? – JohnEye Jun 05 '17 at 11:14
  • Having a full command line for you java process (8778) would be very helpful to debug this. Also make sure that you don't have `rmiregistry` (http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/rmiregistry.html), running as a separate process (throught it will normally display as /rmiregistry in the netstat output). Other options is that you have some JVM agent (jar) attached, which start the registry inside it. – zeppelin Jun 05 '17 at 14:37
  • 3
    Maybe you can stop your application, run another application which listened on port 1099. Then start your application again. The `Address already in use` error should display in log file and indicate the class that listened on port 1099. – Beck Yang Jun 06 '17 at 07:26
  • @beckyang: Good lateral thinking there. I will definitely try it. – JohnEye Jun 06 '17 at 11:10
  • 1
    Could it be that Tomcat itself have opened the port? JMX port often opened for managment purpose. I have seen code where you can register JMX beans on certain port. Port 1099 could also be used for JNDI service, if memory serves me right. – Minh Kieu Jun 06 '17 at 15:15
  • Check if your application somewhere is creating registry on that port. – Jimmy Jun 06 '17 at 20:58
  • 1
    @beckyang: You win, your approach helped me identify the issue pretty fast. Post it as an answer so that I can assign the bounty ;-) – JohnEye Jun 09 '17 at 10:07

1 Answers1

2

Here is the steps to trace the issue:

  1. Stop your application
  2. Run another application which listened on port 1099
  3. Start your application again
  4. java.net.BindException: Address already in use exception is thrown by the class that tries to listen on port 1099.

You can work on the issue based on the clue.

JohnEye
  • 6,436
  • 4
  • 41
  • 67
Beck Yang
  • 3,004
  • 2
  • 21
  • 26