[GE issues] [Issue 3098] New - resource leak in juti - streams not closed after command execution

zwierzak Ryszard.Macidlowski at sun.com
Fri Aug 7 10:47:30 BST 2009


http://gridengine.sunsource.net/issues/show_bug.cgi?id=3098
                 Issue #|3098
                 Summary|resource leak in juti - streams not closed after comma
                        |nd execution
               Component|gridengine
                 Version|6.2u3
                Platform|Sun
                     URL|
              OS/Version|All
                  Status|NEW
       Status whiteboard|
                Keywords|
              Resolution|
              Issue type|DEFECT
                Priority|P3
            Subcomponent|kernel
             Assigned to|andreas
             Reported by|zwierzak






------- Additional comments from zwierzak at sunsource.net Fri Aug  7 02:47:26 -0700 2009 -------
Description:

When called in sequence one after another command (script) using Expect util, the eaten file descriptors can be observed.

Evaluation:

P3. Affects "clients" of juti.jar that use it for sge_ca calls. (Hedeby)

Workaroud/Suggested fix:

No workaround. Fix should close outstanding streams.

Analysis:

The problem is Expect.java in exec() method, after execution the streams should be closed.
Line 238: block of close stream like: process.getOutputStream.close() should be added to ensure that after leaving this method streams are
closed.

How to test:

Manually. External sample application that runs in SUN JVM that allows obtain information about open filedescriptors (based on one of
hedebys junit tests).
Example:

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     UnixOperatingSystemMXBeanWrapper f;
     // try to get a UnixOperatingSystemMXBean. This bean can report open file handles
        OperatingSystemMXBean osMbean = ManagementFactory.getOperatingSystemMXBean();
        f = new UnixOperatingSystemMXBeanWrapper(osMbean);
     for (int i =0; i<10000; i++) {
        try {
            System.out.println("Max: "+f.getMaxFileDescriptorCount()+" Open: "+f.getOpenFileDescriptorCount());
            Expect cmd = new Expect(new String[]{"/tmp/test.sh"});
            System.out.println("Result: "+ i +" : "+cmd.exec(60000));
            System.out.println("Max: "+f.getMaxFileDescriptorCount()+" Open: "+f.getOpenFileDescriptorCount());
            
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchMethodException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    }
    /**
     * In JDK 1.5 there is an OperatingSystemMXBean that may implement the
     * vendor specific interface com.sun.management.UnixOperatingSystemMXBean
     * This interface is needed to get hold on the open file descriptor count
     * The class that ensures that the test will not fail because of vendor specific
     * code
     */
    static class UnixOperatingSystemMXBeanWrapper {
        // Generic type <?> is needed to suppress warnings in Java 1.6
        // see http://java.sun.com/javase/6/docs/technotes/guides/reflection/enhancements.html
        private Class<?> UnixOperatingSystemMXBeanClass;
        private OperatingSystemMXBean osMXBean;

        /**
         * Takes an OperatingSystemMXBean
         * @param osMXBean
         */
        UnixOperatingSystemMXBeanWrapper(OperatingSystemMXBean osMXBean) {
            this.osMXBean = osMXBean;
            //search all interfaces of the OperatingSystemMXBean object if it implements com.sun.management.UnixOperatingSystemMXBean
            Class[] allInterfaces = osMXBean.getClass().getInterfaces();
            for (Class curInterface : allInterfaces) {
                if (curInterface.getCanonicalName().equals("com.sun.management.UnixOperatingSystemMXBean")) {
                    UnixOperatingSystemMXBeanClass = curInterface;
                    break;
                }
            }
        }

        /**
         * @return maxFileDescriptorCount or -1 if not supported
         * @throws java.lang.Exception
         */
        long getMaxFileDescriptorCount() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
            if (!isFileDescriptorMonitoringSupported()) {
                return -1;
            }
            Method getMaxFileDescriptorCountMethod = UnixOperatingSystemMXBeanClass.getDeclaredMethod("getMaxFileDescriptorCount");
            return (Long) getMaxFileDescriptorCountMethod.invoke(osMXBean);
        }

        /**
         * @return openFileDescriptorCount or -1 if not supported
         * @throws java.lang.Exception
         */
        long getOpenFileDescriptorCount() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
            if (!isFileDescriptorMonitoringSupported()) {
                return -1;
            }
            Method getOpenFileDescriptorCountMethod = UnixOperatingSystemMXBeanClass.getDeclaredMethod("getOpenFileDescriptorCount");
            return (Long) getOpenFileDescriptorCountMethod.invoke(osMXBean);
        }

        /**
         * @return true if UnixOperatingSystemMXBean is supported
         * @throws java.lang.Exception
         */
        boolean isFileDescriptorMonitoringSupported() {
            return (UnixOperatingSystemMXBeanClass != null);
        }
    }

}

------------------------------------------------------
http://gridengine.sunsource.net/ds/viewMessage.do?dsForumId=36&dsMessageId=211346

To unsubscribe from this discussion, e-mail: [issues-unsubscribe at gridengine.sunsource.net].



More information about the gridengine-users mailing list