tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 26025] New: - Jasper leaks file descriptors when checking for outdated pages
Date Fri, 09 Jan 2004 17:09:12 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26025>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26025

Jasper leaks file descriptors when checking for outdated pages

           Summary: Jasper leaks file descriptors when checking for outdated
                    pages
           Product: Tomcat 4
           Version: 4.0 Beta 1
          Platform: Sun
        OS/Version: Solaris
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Jasper
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: waraujo@juniper.net


Every time Jasper checks for modified pages, it opens a URL connection to that 
resource to check the modification time and never closes it. Normally it's not 
a problem, since the FD will be freed when the object is garbage collected. 
However, when running on systems with more heap and less frequent GC events, 
the system runs out of FDs before the GC is invoked.
I noticed this problem in Jetty4.2.6, never with Tomcat. I'm providing a patch 
for this problem when the WAR file is extracted. When this is not the case, I 
don't know how to fix it. The patch follows.

--- Compiler.java.orig  Mon Oct 27 16:24:08 2003
+++ Compiler.java       Thu Jan  8 15:17:42 2004
@@ -63,6 +63,8 @@
 import java.util.*;
 import java.io.*;
 import java.net.URL;
+import java.net.URLConnection;
+
 import javax.servlet.jsp.tagext.TagInfo;
 import javax.servlet.ServletException;
 import javax.servlet.Servlet;
@@ -407,7 +409,11 @@
                 ctxt.incrementRemoved();
                 return false;
             }
-            jspRealLastModified = jspUrl.openConnection().getLastModified();
+            
+            // FIX: closes the stream to avoid FD leak
+            URLConnection conn = jspUrl.openConnection();        
+            jspRealLastModified = conn.getLastModified();
+            conn.getInputStream().close();
         } catch (Exception e) {
             e.printStackTrace();
             return true;
@@ -468,11 +474,15 @@
                     //System.out.println("Compiler: outdated, no includeUri " 
+ include );
                     return true;
                 }
-                if (includeUrl.openConnection().getLastModified() >
-                    targetLastModified) {
+                // FIX: closes the stream to avoid FD leak
+                URLConnection conn = includeUrl.openConnection();
+                if(conn.getLastModified() > targetLastModified)
+                {
+                    conn.getInputStream().close();
                     //System.out.println("Compiler: outdated, include old " + 
include );
                     return true;
                 }
+                conn.getInputStream().close();
             } catch (Exception e) {
                 e.printStackTrace();
                 return true;

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message