Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-3651

ClassPathResource.getLastModified() leaks a file descriptor

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 5.5.0.CR1
    • 5.4.0.Final, 5.5.0.Beta1
    • drools-core
    • None
    • Hide
      URL jarURL = new URL("jar:file:/path/to/myjar.jar!/foo.txt");
      JarURLConnection connection = (JarURLConnection) jarURL.openConnection();
      try {
          long lastModified = connection.getLastModified();
      } finally {
          connection.getInputStream().close();
      }
      Thread.sleep(300000);

      Now check the file descriptors in /proc/<java PID>/fd (Linux) to see that there is still one open for the JAR.

      Not that ClassPathResource.getLastModified() makes any attempt to close this file descriptor in the first place.

      Show
      URL jarURL = new URL( "jar:file:/path/to/myjar.jar!/foo.txt" ); JarURLConnection connection = (JarURLConnection) jarURL.openConnection(); try { long lastModified = connection.getLastModified(); } finally { connection.getInputStream().close(); } Thread .sleep(300000); Now check the file descriptors in /proc/<java PID>/fd (Linux) to see that there is still one open for the JAR. Not that ClassPathResource.getLastModified() makes any attempt to close this file descriptor in the first place.
    • Hide

      Use the "concurrent mark-and-sweep" garbage collector, to ensure that objects are finalized promptly?

      Show
      Use the "concurrent mark-and-sweep" garbage collector, to ensure that objects are finalized promptly?

    Description

      Calling getLastModified() on a ClassPathResource allocates a file descriptor and doesn't release it until the ClassPathResource object is garbage-collected.

      I believe that this is a bug in JarURLConnection in Sun's JDK6, as noticed by the Freemarker project, who also created a fix.

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            chrisjr_jira Chris Rankin (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

            Dates

              Created:
              Updated:
              Resolved:
              Archived:

              PagerDuty