tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Renato <rewei...@yahoo.com>
Subject [Patch] File descriptor leak in ManagerBase - please advise.
Date Mon, 30 Aug 2004 17:43:24 GMT
Hi all,

I running linux with tomcat 5.0.28. Today I have the
following error:

java.net.SocketException: Too many open files
        at java.net.Socket.createImpl(Socket.java:331)
        at java.net.Socket.<init>(Socket.java:304)
        at java.net.Socket.<init>(Socket.java:124)
(...)

By checking with 'lsof -p "tomcat_pid"', I saw that
there thousands of opened /dev/urandom files.

I looked at the code and I found that in class
org/apache/catalina/session/ManagerBase.java, the
/dev/urandom is opened but apparently never closed...
( any reason ? )

I made this patch and it fixed my problem, with no
colateral effected so far...

---
../jakarta-tomcat-5.0.27-src/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/ManagerBase.java
     2004-06-17 22:11:20.000000000 -0300
+++
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/ManagerBase.java
    2004-08-30 14:23:43.000000000 -0300
@@ -194,10 +194,12 @@
             try {
                 File f=new File( devRandomSource );
                 if( ! f.exists() ) return null;
-                randomIS= new DataInputStream( new
FileInputStream(f));
+                FileInputStream fin = new
FileInputStream(f);
+                randomIS= new DataInputStream(fin);
                 randomIS.readLong();
                 if( log.isDebugEnabled() )
                     log.debug( "Opening " +
devRandomSource );
+                fin.close();
                 return randomIS;
             } catch (IOException ex){
                 return null;
@@ -505,10 +507,12 @@
                     devRandomSource=s;
                     File f=new File( devRandomSource
);
                     if( ! f.exists() ) return;
-                    randomIS= new DataInputStream(
new FileInputStream(f));
+                    FileInputStream fin = new
FileInputStream(f);
+                    randomIS= new
DataInputStream(fin);
                     randomIS.readLong();
                     if( log.isDebugEnabled() )
                         log.debug( "Opening " +
devRandomSource );
+                   fin.close();
                 } catch( IOException ex ) {
                     randomIS=null;
                 }

Any comment ?
Thanks for the attention
Renato - Brazil.



		
_______________________________
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush

---------------------------------------------------------------------
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