Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jersey-dev] "Connection pool shut down" using ApacheConnectorProvider and PoolingHttpClientConnectionManager

The Client is registered in the ResourceConfig like this:

        register(new AbstractBinder()
        {
            @Override
            protected void configure()
            {
                bind(client).to(Client.class);
            }
        });

On Thu, Apr 23, 2020 at 9:52 PM Martynas Jusevičius
<martynas@xxxxxxxxxxxxx> wrote:
>
> Hi,
>
> hitting hopefully the last hurdle in the upgrade to 2.30.1.
>
> Attempting to recreate the setup that used ApacheHttpClient4Handler
> with Jersey 1.19, I configured Client with ApacheConnectorProvider and
> replaced the deprecated ThreadSafeClientConnManager with
> PoolingHttpClientConnectionManager:
>
>             TrustManagerFactory tmf =
> TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
>             tmf.init(trustStore);
>
>             SSLContext ctx = SSLContext.getInstance("SSL");
>             ctx.init(null, tmf.getTrustManagers(), null);
>
>             Registry<ConnectionSocketFactory> socketFactoryRegistry =
> RegistryBuilder.<ConnectionSocketFactory>create().
>                 register("https", new SSLConnectionSocketFactory(ctx)).
>                 register("http", new PlainConnectionSocketFactory()).
>                 build();
>
>             PoolingHttpClientConnectionManager conman = new
> PoolingHttpClientConnectionManager(socketFactoryRegistry);
>             conman.setDefaultMaxPerRoute(20);
>
>             ClientConfig config = new ClientConfig();
>             config.connectorProvider(new ApacheConnectorProvider());
>             config.register(...);
>             config.property(ApacheClientProperties.CONNECTION_MANAGER, conman);
>             config.property(ClientProperties.FOLLOW_REDIRECTS, true);
>
>             return ClientBuilder.newBuilder().
>                 withConfig(config).
>                 sslContext(ctx).
>                 hostnameVerifier(NoopHostnameVerifier.INSTANCE).
>                 build();
>
> I also take care to close Responses:
>
>         try (Response cr = query(query, Model.class, null))
>         {
>             return cr.readEntity(Model.class);
>         }
>
> However just after a dozen or so requests after the webapp starts, I get this:
>
> Exception
>
> javax.servlet.ServletException: javax.ws.rs.ProcessingException:
> java.lang.IllegalStateException: Connection pool shut down
> org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:410)
> org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366)
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319)
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
> org.apache.catalina.filters.HttpHeaderSecurityFilter.doFilter(HttpHeaderSecurityFilter.java:126)
>
> Root Cause
>
> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
> Connection pool shut down
> org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:528)
> org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:296)
> org.glassfish.jersey.client.JerseyInvocation.lambda$invoke$0(JerseyInvocation.java:609)
> org.glassfish.jersey.internal.Errors.process(Errors.java:292)
> org.glassfish.jersey.internal.Errors.process(Errors.java:274)
> org.glassfish.jersey.internal.Errors.process(Errors.java:205)
> org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:390)
> org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:608)
> org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:395)
> org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:295)
> com.atomgraph.core.client.ClientBase.get(ClientBase.java:101)
> com.atomgraph.core.client.SPARQLClient.query(SPARQLClient.java:107)
> com.atomgraph.linkeddatahub.server.model.impl.ResourceBase.describe(ResourceBase.java:869)
> com.atomgraph.core.model.impl.QueriedResourceBase.get(QueriedResourceBase.java:120)
> com.atomgraph.server.model.impl.ResourceBase.get(ResourceBase.java:249)
> com.atomgraph.linkeddatahub.server.model.impl.ResourceBase.get(ResourceBase.java:228)
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> java.lang.reflect.Method.invoke(Method.java:498)
> org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
> org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124)
> org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167)
> org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176)
> org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
> org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:469)
> org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:391)
> org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:80)
> org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:253)
> org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
> org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
> org.glassfish.jersey.internal.Errors.process(Errors.java:292)
> org.glassfish.jersey.internal.Errors.process(Errors.java:274)
> org.glassfish.jersey.internal.Errors.process(Errors.java:244)
> org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
> org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:232)
> org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:680)
> org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
> org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366)
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319)
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
> org.apache.catalina.filters.HttpHeaderSecurityFilter.doFilter(HttpHeaderSecurityFilter.java:126)
>
> I can also see in the logs that Finalizer might something to do with
> this - this happens consistently before/around when the exception is
> thrown:
> | [0m 21:45:01,100 [Finalizer] DEBUG
> PoolingHttpClientConnectionManager:409 - Connection manager is
> shutting down
> | [0m 21:45:01,109 [Finalizer] DEBUG
> DefaultManagedHttpClientConnection:79 - http-outgoing-1: Close
> connection
> | [0m 21:45:01,110 [Finalizer] DEBUG
> PoolingHttpClientConnectionManager:415 - Connection manager shut down
>
> After searching online, it looks like the HTTPClient is shutdown, but
> I don't get why or where Jersey would do that.
>
> Can this be a bug or a problem in our code?
>
>
> Martynas


Back to the top