Bug 54702 - File descriptor leak at web.xml loading
File descriptor leak at web.xml loading
Status: RESOLVED FIXED
Product: Tomcat 7
Classification: Unclassified
Component: Catalina
7.0.33
PC All
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2013-03-15 08:53 UTC by Jean-Marie LAMARE
Modified: 2013-03-15 15:11 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Marie LAMARE 2013-03-15 08:53:36 UTC
Hello

I think I've found a file descriptor leak in file /tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (method getGlobalWebXmlSource).

A stream is from file "web.xml" is not closed.

private WebXml getDefaultWebXmlFragment() {
... 

1284	        InputSource globalWebXml = getGlobalWebXmlSource();
...
1337	            // Parse global web.xml if present
1338	            if (globalWebXml == null) {
1339	                // This is unusual enough to log
1340	                log.info(sm.getString("contextConfig.defaultMissing"));
1341	            } else {
1342	                parseWebXml(globalWebXml, webXmlDefaultFragment, false);
1343	            }

Here is the full stack trace

[java.io.FileInputStream.<init>(FileInputStream.java:109)] [org.apache.catalina.startup.ContextConfig.getWebXmlSource(ContextConfig.java:1837)] [org.apache.catalina.startup.ContextConfig.getGlobalWebXmlSource(ContextConfig.java:1744)] [org.apache.catalina.startup.ContextConfig.getDefaultWebXmlFragment(ContextConfig.java:1417)] [org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1253)] [org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)] [org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)] [org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)] [org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)] [org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)] [org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)] [org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)] [org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)] [org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)] [org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)] [org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:542)] [org.apache.catalina.startup.HostConfig.check(HostConfig.java:1462)] [sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)] [sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)] [sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)] [java.lang.reflect.Method.invoke(Method.java:597)] [org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)] [com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)] [com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)] [org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1445)] [org.apache.catalina.manager.HTMLManagerServlet.upload(HTMLManagerServlet.java:301)] [org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:208)] [javax.servlet.http.HttpServlet.service(HttpServlet.java:647)] [javax.servlet.http.HttpServlet.service(HttpServlet.java:728)] [org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)] [org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)] [org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)] [org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)] [org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)] [org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)] [org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)] [org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)] [org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)] [org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)] [org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)] [org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)] [org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)] [org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)] [org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)] [org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)] [org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)] [org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)] [org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)] [java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)] [java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)] [java.lang.Thread.run(Thread.java:662)]
Comment 1 Violeta Georgieva 2013-03-15 09:27:49 UTC
Hi,

Did you observe that in some real situation?

Basically the following is specified for org.xml.sax.InputSource [1]

"However, standard processing of both byte and character streams is to close them on as part of end-of-parse cleanup, so applications should not attempt to re-use such streams after they have been handed to a parser."


Regards
Violeta
[1] http://docs.oracle.com/javase/6/docs/api/
Comment 2 Jean-Marie LAMARE 2013-03-15 10:33:34 UTC
Hello

The following file are opened after a WAR deployment on my computer (I've used the command handle written by the sys internal team).

java.exe pid: 3984 CASTCORP\JML
    C: File  (RW-)   C:\java\apache-tomcat-7.0.33\bin
   54: File  (R-D)   C:\TEMP\hsperfdata_jml\3984
   5C: Section       \Sessions\1\BaseNamedObjects\hsperfdata_JML_3984
   E0: File  (RW-)   C:\java\jdk1.6.0_35_x64\jre\lib\rt.jar
  1E8: File  (RW-)   C:\java\apache-tomcat-7.0.33\bin\bootstrap.jar
  1EC: File  (RW-)   C:\java\apache-tomcat-7.0.33\bin\commons-daemon.jar
  1F0: File  (RW-)   C:\java\apache-tomcat-7.0.33\bin\tomcat-juli.jar
  1F4: File  (RW-)   C:\java\apache-tomcat-7.0.33\logs\catalina.2013-03-15.log
  1F8: File  (RW-)   C:\java\apache-tomcat-7.0.33\logs\localhost.2013-03-15.log
  1FC: File  (RW-)   C:\java\apache-tomcat-7.0.33\logs\manager.2013-03-15.log
  200: File  (RW-)   C:\java\apache-tomcat-7.0.33\logs\host-manager.2013-03-15.log
  204: File  (RW-)   C:\java\jdk1.6.0_35_x64\jre\lib\jsse.jar
  208: File  (RW-)   C:\java\jdk1.6.0_35_x64\jre\lib\ext\dnsns.jar
  20C: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\annotations-api.jar
  210: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\catalina-ant.jar
  214: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\catalina-ha.jar
  218: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\catalina-tribes.jar
  21C: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\catalina.jar
  220: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\ecj-3.7.2.jar
  224: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\el-api.jar
  228: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\jasper-el.jar
  22C: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\jasper.jar
  230: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\jsp-api.jar
  234: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\servlet-api.jar
  238: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\tomcat-api.jar
  23C: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\tomcat-coyote.jar
  240: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\tomcat-dbcp.jar
  244: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\tomcat-i18n-es.jar
  248: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\tomcat-i18n-fr.jar
  24C: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\tomcat-i18n-ja.jar
  250: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\tomcat-jdbc.jar
  254: File  (RW-)   C:\java\apache-tomcat-7.0.33\lib\tomcat-util.jar
  27C: File  (RW-)   C:\java\jdk1.6.0_35_x64\jre\lib\ext\localedata.jar
  288: File  (RW-)   C:\java\jdk1.6.0_35_x64\jre\lib\resources.jar
  304: File  (RW-)   C:\java\jdk1.6.0_35_x64\jre\lib\jce.jar
  308: File  (RW-)   C:\java\jdk1.6.0_35_x64\jre\lib\ext\sunjce_provider.jar
  31C: File  (R-D)   C:\Windows\System32\en-US\KernelBase.dll.mui
  338: File  (RW-)   C:\java\jdk1.6.0_35_x64\jre\lib\charsets.jar
  33C: File  (RW-)   C:\java\apache-tomcat-7.0.33\logs\localhost_access_log.2013-03-15.txt
  354: File  (RW-)   C:\java\jdk1.6.0_35_x64\jre\lib\charsets.jar
  440: File  (RW-)   C:\java\apache-tomcat-7.0.33\conf\web.xml
  454: File  (RW-)   C:\java\apache-tomcat-7.0.33\conf\web.xml
  964: File  (RW-)   C:\java\apache-tomcat-7.0.33\temp\system4547162881526958771.jar
  990: File  (RW-)   C:\java\apache-tomcat-7.0.33\temp\bootstrap5643731443438317122.jar
  9A8: File  (RW-)   C:\workspaces\pmc_Contrex\jvmagent\jvmagent.jar

So the sys internal utility observes it in a real situation.

I've discoverer this bug thanks a JVM agent which rewrites FileInputStream and FileOutputStream bytecodes. 
This one ensures that FileInputStream.close is called after the constructor invocation.
Comment 3 Jean-Marie LAMARE 2013-03-15 11:47:15 UTC
Is the bugs due to a missing close call there ?

1312	        if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp &&
1313	                entry.getHostTimeStamp() == hostTimeStamp) {
1314	            return entry.getWebXml();
1315	        }
...
1321	            entry = hostWebXmlCache.get(host);
1322	            if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp &&
1323	                    entry.getHostTimeStamp() == hostTimeStamp) {
1324	                return entry.getWebXml();
1325	            }

Sometimes, the web.xml file is not parsed and the stream is not closed
Comment 4 Violeta Georgieva 2013-03-15 15:11:52 UTC
Thanks for the report.
Fixed in trunk and 7.0.x and will be included in 7.0.39 onwards.