JDK-7162955 : Attach api on Solaris, too many open files
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc
  • Affected Version: 6u26,6u31
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_10
  • CPU: x86,sparc
  • Submitted: 2012-04-19
  • Updated: 2014-03-03
  • Resolved: 2012-05-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 6 JDK 7 JDK 8 Other
6u33Resolved 7u21Resolved 8Resolved hs20.9Resolved
Description
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)

ADDITIONAL OS VERSION INFORMATION :
SunOS qs-sol10-64-a 5.10 Generic_139556-08 i86pc i386 i86pc

A DESCRIPTION OF THE PROBLEM :
My Java application connects to other JVMs using attach api to be able to connect with JMX after.

Works well on windows and linux. Almost on Solaris. The problem on solaris is the number of open file for each JVM receiving attach connection and the one creating it always increase. After few days it was 10k open files for each JVM.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
 - Run sample with one arg to have a running JVM.
 - Run sample with no arg to attach on the other one.
 - Check open files for the first JVM process while attach/detach JVMs.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Number of open files should remain stable.
ACTUAL -
Number of open files always increase.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
None.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package attach;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Properties;

import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;

public class Main {

    public static void main(String[] args) {
        if (args.length == 1) {
            int i = 0;
            while (true) {
                i++;
                try {
                    Thread.sleep(10000L);
                } catch (InterruptedException e) {
                }
            }
        } else {
            getVmInfos();
        }
    }

    public static void getVmInfos() {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String tmp;
        boolean again = true;

        while (again) {
            List<VirtualMachineDescriptor> vms = VirtualMachine.list();
            for (VirtualMachineDescriptor vmd : vms) {

                System.out.println("Name: " + vmd.displayName() + " , id: " + vmd.id() + ", Tostring: " + vmd.toString());

                try {
                    VirtualMachine vm = VirtualMachine.attach(vmd);
                    Properties agentProps = vm.getAgentProperties();

                    System.out.println("Detach? ");
                    tmp = br.readLine();
                    if (tmp.startsWith("y")) {
                        vm.detach();
                    }

                } catch (AttachNotSupportedException x) {
                    x.printStackTrace();
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
            
            try {
                System.out.println("Again? ");
                tmp = br.readLine();
                again = tmp.startsWith("y");
            } catch (IOException e) {
                e.printStackTrace();
            }
            
        }
    }

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use linux :P

Comments
EVALUATION http://hg.openjdk.java.net/lambda/lambda/hotspot/rev/973046802b6f
2012-06-29

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-rt/hotspot/rev/973046802b6f
2012-05-12

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-emb/hotspot/rev/973046802b6f
2012-04-27

EVALUATION Need to release server-side socket after client receives it.
2012-04-26