Bug 52746 - Classloader closed in middle of webapp deployment
Summary: Classloader closed in middle of webapp deployment
Status: RESOLVED DUPLICATE of bug 53225
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.16
Hardware: PC Linux
: P2 regression (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on: 53225
Blocks:
  Show dependency tree
 
Reported: 2012-02-23 12:16 UTC by Fred Simon
Modified: 2012-05-31 10:38 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fred Simon 2012-02-23 12:16:25 UTC
We have an application were all the jars reside in the shared (or common) classloader of Tomcat, and then we are starting multiple webapp using the common jars.
This setup works good with Java 1.6 and 1.7 on Tomcat 7.0.14.
When using Tomcat 7.0.16-19-22 and 26 (the 4 versions I tested), on both JVM, we are getting the following for a random number of webapps (4 out of 11 always deploys, 7 fails) on a single tomcat instance.

So, we tried to debug when, who, why the “java.util.zip.InflaterInputStream” was closed before the web application finished loading the resources and classes.
In debug mode with a breaking point on “java.util.zip.InflaterInputStream#close” of course the bug does not happens :(
We tested with JDK 1.7.0_01 and 1.6.0_20, on Tomcat 7.0.16, 7.0.19, 7.0.22, 7.0.26. On all configurations we got the issue.

This error appears on all kind of resources from the jar (xml, properties, classes, …), during a tomcat call to "javax.servlet.ServletContextListener#contextInitialized".

For java 7 we got:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-INF/spring/addons.xml]; nested exception is java.io.IOException: Stream closed
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:408) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
Caused by: java.io.IOException: Stream closed
	at java.util.zip.InflaterInputStream.ensureOpen(InflaterInputStream.java:67) [na:1.7.0_01]
	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:121) [na:1.7.0_01]
	at java.io.FilterInputStream.read(FilterInputStream.java:83) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2905) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2937) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:302) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1750) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanLiteral(XMLEntityScanner.java:1071) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPseudoAttribute(XMLScanner.java:590) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanXMLDeclOrTextDecl(XMLScanner.java:407) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanXMLDeclOrTextDecl(XMLDocumentFragmentScannerImpl.java:913) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$XMLDeclDriver.next(XMLDocumentScannerImpl.java:775) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:430) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:240) [na:1.7.0_01]
	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300) [na:1.7.0_01]
	at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388) [spring-beans-3.0.6.RELEASE.jar:3.0.6.RELEASE]
	... 20 common frames omitted

For Java 6 we got:
Caused by: java.util.zip.ZipException: ZipFile closed
        at java.util.zip.ZipFile.ensureOpenOrZipException(ZipFile.java:413) [na:1.6.0_20]
        at java.util.zip.ZipFile.access$1100(ZipFile.java:29) [na:1.6.0_20]
        at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:445) [na:1.6.0_20]
        at java.util.zip.ZipFile$1.fill(ZipFile.java:230) [na:1.6.0_20]
        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:141) [na:1.6.0_20]
        at java.io.FilterInputStream.read(FilterInputStream.java:116) [na:1.6.0_20]
        at org.springframework.asm.ClassReader.a(Unknown Source) [spring-asm-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.asm.ClassReader.<init>(Unknown Source) [spring-asm-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:48) [spring-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80) [spring-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101) [spring-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76) [spring-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter.match(AbstractTypeHierarchyTraversingFilter.java:105) [spring-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter.match(AbstractTypeHierarchyTraversingFilter.java:76) [spring-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isCandidateComponent(ClassPathScanningCandidateComponentProvider.java:280) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:214) [spring-context-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        ... 29 common frames omitted

We saw that the GC finalizer is closing the zip on finalize. Playing with “-XX:+UseConcMarkSweepGC -XX:+UseParNewGC” has no effect.
Comment 1 Mark Thomas 2012-03-07 10:51:52 UTC
I don't see any Tomcat code in those stack traces therefore it is hard to see how this could be a Tomcat issue.

Tomcat did change the it's own JAR scanning code between 7.0.14 and 7.0.16 but since that runs before any application code, it is hard to see how that may impact the application. I did double check it ensure all JARS and InputStreams that are opened are closed and I didn't see any gaps.

Absent any evidence that points to a Tomcat issue then there isn't much that can be done.
Comment 2 Igor Mihalik 2012-05-18 18:21:26 UTC
There's a workaround for this issue to use:
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" urlCacheProtection="true"/>

which is used by default in default server.xml configuration file, but if you removed the listener completely you can encounter this problem. It is very likely it was introduced by this improvement: https://issues.apache.org/bugzilla/show_bug.cgi?id=51276
svn revision: r1130497
Comment 3 Konstantin Kolinko 2012-05-31 10:38:04 UTC
Marking as DUPLICATE of bug 53225.

*** This bug has been marked as a duplicate of bug 53225 ***