On Thu, Apr 8, 2021 at 1:01 PM Rainer Jung <rainer.j...@kippdata.de> wrote:
> Hi Remy, > > Filip wrote in the git commit message "Avoid having to load APR classes > in the Connector". If this is an important goal for TC 9, we would need > some other place during TC startup that loads the APR classes before the > connector gets instantiated. I don't know, what a good place would be. > Currently it seems, the connector gets instantiated while the digester > processes server.xml, and the Lifecycle events that would init the > AprLifecycleListener start after that phase, so too late for the > connector. Not sure whether it would be feasible to use a digester end > method in a rule for the AprLifecycleListener to call its static init() > after it has configured the class. > > My patch simply reverts the part of Filip's change in the Connector > class related to isAprAvailable() back to the 9.0.37 situation. > I think it should be fine now since AprStatus allows avoiding using AprLIfecycleListener if it is not configured. > > Using explicit className surely is possible, but I think we shouldn't > break the well known and documented auto-behavior in TC up until 9. For > example our Windows binary distribution contains tcnative, so each TC 9 > installed with that download and having edited server.xml with > useAprConnector="true" automatically switches to the APR connectoer, If > people update after 9.0.37, it will no longer use APR without being made > aware. > > Concerning the three places in Connector, I agree, that only the first > is needed. > All good then. Rémy > > Regards, > > Rainer > > Am 08.04.2021 um 09:29 schrieb Rémy Maucherat: > > On Wed, Apr 7, 2021 at 2:42 PM Rainer Jung <rainer.j...@kippdata.de> > wrote: > > > >> The only direct calls to AprStatus.isAprAvailable() outside of the > >> APRLifecycleListener itself are actually in Connector.java. Replacing > >> those by calls to the listener seems to work for me: > >> > >> diff --git a/java/org/apache/catalina/connector/Connector.java > >> b/java/org/apache/catalina/connector/Connector.java > >> index 1cc15802eb..53a210e6b2 100644 > >> --- a/java/org/apache/catalina/connector/Connector.java > >> +++ b/java/org/apache/catalina/connector/Connector.java > >> @@ -29,6 +29,7 @@ import org.apache.catalina.Globals; > >> import org.apache.catalina.LifecycleException; > >> import org.apache.catalina.LifecycleState; > >> import org.apache.catalina.Service; > >> +import org.apache.catalina.core.AprLifecycleListener; > >> import org.apache.catalina.core.AprStatus; > >> import org.apache.catalina.util.LifecycleMBeanBase; > >> import org.apache.coyote.AbstractProtocol; > >> @@ -80,7 +81,7 @@ public class Connector extends LifecycleMBeanBase { > >> > >> > >> public Connector(String protocol) { > >> - boolean apr = AprStatus.isAprAvailable() && > >> + boolean apr = AprLifecycleListener.isAprAvailable() && > >> > > > > Ok, so I thought only the first change was significant, the others occur > > after AprLifecycleListener runs its init so it should work just fine. > > > > Rémy > > > > > >> AprStatus.getUseAprConnector(); > >> ProtocolHandler p = null; > >> try { > >> @@ -1020,11 +1021,11 @@ public class Connector extends > LifecycleMBeanBase > >> { > >> throw new > >> > >> > LifecycleException(sm.getString("coyoteConnector.protocolHandlerNoAprListener", > >> getProtocolHandlerClassName())); > >> } > >> - if (protocolHandler.isAprRequired() && > >> !AprStatus.isAprAvailable()) { > >> + if (protocolHandler.isAprRequired() && > >> !AprLifecycleListener.isAprAvailable()) { > >> throw new > >> > >> > LifecycleException(sm.getString("coyoteConnector.protocolHandlerNoAprLibrary", > >> getProtocolHandlerClassName())); > >> } > >> - if (AprStatus.isAprAvailable() && AprStatus.getUseOpenSSL() && > >> + if (AprLifecycleListener.isAprAvailable() && > >> AprStatus.getUseOpenSSL() && > >> protocolHandler instanceof > AbstractHttp11JsseProtocol) { > >> AbstractHttp11JsseProtocol<?> jsseProtocolHandler = > >> (AbstractHttp11JsseProtocol<?>) protocolHandler; > >> > >> Feel free to apply. > >> > >> Regards, > >> > >> Rainer > >> > >> > >> Am 07.04.2021 um 14:32 schrieb Rainer Jung: > >>> I think the reason is: > >>> > >>> o.a.c.connector.Connector checks AprStatus.isAprAvailable(). It > >>> previously checked AprLifecycleListener.isAprAvailable(). The > difference > >>> is, that the old AprLifecycleListener.isAprAvailable() triggers the > >>> init() of AprLifecycleListener, whereas AprStatus.isAprAvailable() does > >>> not. > >>> > >>> I think isAprAvailable() is the only method with side effects that was > >>> moved from AprLifecycleListener to AprStatus. Since it is still > >>> available in AprLifecycleListener, I think it would be safest to > >>> typically not call it in AprStatus but instead in AprLifecycleListener. > >>> > >>> Regards, > >>> > >>> Rainer > >>> > >>> Am 07.04.2021 um 14:02 schrieb Rainer Jung: > >>>> Maybe related to f4dac6846c548144799b1c3f33aba4eb320a3413. > >>>> > >>>> Am 07.04.2021 um 13:53 schrieb Rainer Jung: > >>>>> Hi there, > >>>>> > >>>>> a colleague of mine observed a change in behavior starting with TC > >>>>> 9.0.38: until 9.0.37 the default server.xml with the connector > >>>>> protocol="HTTP/1.1", installed tcnative and attribute > >>>>> useAprConnector="true" for the AprLifecycleListener actually starts > >>>>> an APR connector as documented and expected: > >>>>> > >>>>> INFO [main] org.apache.coyote.AbstractProtocol.init Initializing > >>>>> ProtocolHandler ["http-apr-8080"] > >>>>> > >>>>> Same situation starting with 9.0.38 (and at least until 9.0.44): > >>>>> > >>>>> INFO [main] org.apache.coyote.AbstractProtocol.init Initializing > >>>>> ProtocolHandler ["http-nio-8080"] > >>>>> > >>>>> I increased log level for a coupe of packages to FINEST and see the > >>>>> following differences during startup: > >>>>> > >>>>> FINE [main] org.apache.tomcat.util.IntrospectionUtils.setProperty > >>>>> IntrospectionUtils: setProperty(class > >>>>> org.apache.catalina.core.AprLifecycleListener SSLEngine=on) > >>>>> FINE [main] org.apache.tomcat.util.digester.SetPropertiesRule.begin > >>>>> [SetPropertiesRule]{Server/Listener} Setting property > >>>>> 'useAprConnector' to 'true' > >>>>> FINE [main] org.apache.tomcat.util.IntrospectionUtils.setProperty > >>>>> IntrospectionUtils: setProperty(class > >>>>> org.apache.catalina.core.AprLifecycleListener useAprConnector=true) > >>>>> ### ONLY ADDRESS DIFFERENCE > >>>>> -FINE [main] org.apache.tomcat.util.digester.SetNextRule.end > >>>>> [SetNextRule]{Server/Listener} Call > >>>>> > >> > org.apache.catalina.core.StandardServer.addLifecycleListener(org.apache.catalina.core.AprLifecycleListener@383534aa > ) > >> > >>>>> > >>>>> +FINE [main] org.apache.tomcat.util.digester.SetNextRule.end > >>>>> [SetNextRule]{Server/Listener} Call > >>>>> > >> > org.apache.catalina.core.StandardServer.addLifecycleListener(org.apache.catalina.core.AprLifecycleListener@136432db > ) > >> > >>>>> > >>>>> FINE [main] org.apache.tomcat.util.IntrospectionUtils.callMethod1 > >>>>> IntrospectionUtils: callMethod1 > >>>>> org.apache.catalina.core.StandardServer > >>>>> org.apache.catalina.core.AprLifecycleListener > >>>>> org.apache.catalina.LifecycleListener > >>>>> FINE [main] org.apache.tomcat.util.digester.ObjectCreateRule.end > >>>>> [ObjectCreateRule]{Server/Listener} Pop > >>>>> org.apache.catalina.core.AprLifecycleListener > >>>>> #### WRONG CLASS CHOSEN IN NEWER VERSIONS > >>>>> -FINE [main] org.apache.tomcat.util.IntrospectionUtils.setProperty > >>>>> IntrospectionUtils: setProperty(class > >>>>> org.apache.coyote.http11.Http11AprProtocol port=8080) > >>>>> +FINE [main] org.apache.tomcat.util.IntrospectionUtils.setProperty > >>>>> IntrospectionUtils: setProperty(class > >>>>> org.apache.coyote.http11.Http11NioProtocol port=8080) > >>>>> FINE [main] org.apache.tomcat.util.digester.SetPropertiesRule.begin > >>>>> [SetPropertiesRule]{Server/Service/Connector} Setting property > >>>>> 'protocol' to 'HTTP/1.1' > >>>>> ... > >>>>> > >>>>> and after these lines the logs use consistenly APR versus NIO in the > >>>>> two versions. Both startup logs show the same > >>>>> > >>>>> INFO [main] > >>>>> org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded > >>>>> Apache Tomcat Native library [1.2.27] using APR version [1.7.0]. > >>>>> INFO [main] > >>>>> org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR > >>>>> capabilities: IPv6 [true], sendfile [true], accept filters [false], > >>>>> random [true]. > >>>>> INFO [main] > >>>>> org.apache.catalina.core.AprLifecycleListener.lifecycleEvent > >>>>> APR/OpenSSL configuration: useAprConnector [true], useOpenSSL [true] > >>>>> INFO [main] > >>>>> org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL > >>>>> successfully initialized [OpenSSL 1.1.1k 25 Mar 2021] > >>>>> > >>>>> I didn't find an obvious reason in the changelog. Maybe an unwanted > >>>>> backport part from 10 or some startup order change. > >>>>> > >>>>> I have not yet checked 8.5 etc. > >>>>> > >>>>> Regards, > >>>>> > >>>>> Rainer > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org > For additional commands, e-mail: dev-h...@tomcat.apache.org > >