gretty-gradle-plugin / gretty

Advanced gradle plugin for running web-apps on jetty and tomcat.
MIT License
129 stars 36 forks source link

Unable to use appRun with Tomcat 9 after updating to Gradle 7.5.1 and Gretty 3.0.8 #272

Closed ndrake closed 1 year ago

ndrake commented 2 years ago

We're in the process of upgrading a project from using Gradle 5.1/Gretty 3.0.3 to Gradle 7.5.1. As part of that work, we updated to Gretty 3.0.8. When using ./gradlew appRun most of the time Tomcat startup fails with the following stacktrace:

java.lang.IllegalStateException: Error starting child
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:729)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:698)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:696)
        at org.apache.catalina.Container$addChild$2.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
        at org.akhikhl.gretty.TomcatServerManager.startServer(TomcatServerManager.groovy:63)
        at org.akhikhl.gretty.ServerManager$startServer$0.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
        at org.akhikhl.gretty.Runner.run(Runner.groovy:135)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:193)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:73)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
        at org.akhikhl.gretty.Runner.main(Runner.groovy:51)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/home]]
        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
        ... 23 common frames omitted
Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/home] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.bouncycastle.asn1.ASN1OutputStream->org.bouncycastle.asn1.DEROutputStream->org.bouncycastle.asn1.DLOutputStream->org.bouncycastle.asn1.ASN1OutputStream]
        at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2404)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2342)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:2294)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:2264)
        at org.apache.catalina.startup.ContextConfig.scanWebXmlFragment(ContextConfig.java:2172)
        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:2152)
        at org.apache.catalina.startup.ContextConfig.processClasses(ContextConfig.java:1408)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1303)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:986)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:303)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5135)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        ... 24 common frames omitted

This doesn't happen ALL the time, but most of the time. Also, when this failure happens, we need to do ./gradlew --stop before trying appRun again our we get "Port in use" errors.

We didn't update any of our application dependencies as part of this work, so I'm not sure why we're running into this now. Running ./gradlew :dependencies shows the same set of Bouncy Castle JARs pre and post Gradle/Gretty upgrade.

bouncycastle:bcprov-jdk14:138
org.bouncycastle:bcprov-jdk15on:1.67
org.bouncycastle:bcprov-jdk15on:1.60

My various attempts to exclude different Bouncy Castle JARs hasn't helped. Has anyone run into this situation? We aren't using Gretty 4.x yet, as we still require Tomcat 9 support at this time.

Our Gretty config looks like this:

gretty {
    contextPath = "/home"
    enableNaming = true
    httpEnabled = false
    httpsEnabled = true
    serverConfigFile = "src/main/config/deployments/${deployment}/tomcat/server.xml"
    servletContainer = "tomcat9"
}
boris-petrov commented 2 years ago

@ndrake this doesn't seem like a Gretty issue. But the multiple Bouncy Castle JARs could definitely cause problems. Why are you having troubles excluding them? Do you use Gradle or Maven?

ndrake commented 1 year ago

Closing this now, as it seems Gretty 3.1.0 has resolved the StackOverflowError we had previously.