Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Starting a new HttpClient after stopping and destroying an HttpClient sometimes fails

Hello,

 

Using embedded Jetty. jetty-home-10.0.11.

 

I have a problem with stopping and destroying and restarting a HttpClient. When stopping an internal component MessagingGatewayFacebook embedding an HttpClient instance, it calls closeHttpClient(). When needing to start the component from a jetty servlet, it calls createHttpClient().

 

private HttpClient httpClient;

 

private void createHttpClient() {

                try {

                               if (httpClient == null) {

                                               SslContextFactory.Client sslContextFactory = new SslContextFactory.Client(true);

                                               ClientConnector clientConnector = new ClientConnector();

                                               clientConnector.setSslContextFactory(sslContextFactory);

                                               httpClient = new HttpClient(new HttpClientTransportDynamic(clientConnector));

                                               httpClient.start();

                                               logger.debug("HttpClient " + httpClient + " started");

                               }

                               httpClient.setConnectTimeout(…);

                               httpClient.setIdleTimeout(…);

                } catch (Exception ex) {

                               logger.error("HttpClient " + httpClient + " cannot be started", ex);

                               httpClient = null;

                }

}

               

private void closeHttpClient() {

                if (httpClient != null) {

                               try {

                                               httpClient.stop();

                                               httpClient.destroy();

                                               logger.debug("HttpClient " + httpClient + " stopped");

                               } catch (Exception ex) {

                                               logger.debug("HttpClient " + httpClient + " cannot be stopped", ex);

                               }

                               httpClient = null;

                }

}

 

closeHttpClient() sets the httpClient to null after stop+destroy on the client.

createHttpClient() creates a new HttpClient.

 

Sometimes (it is not always the case), we get this exception on httpClient.start() showing that the AbstractConnectorHttpClientTransport cannot be started since it has been destroyed !

 

2022-07-28 16:19:36,530 [qtp1875108260-253] ERROR MessagingGatewayFacebook - HttpClient HttpClient@5900f7df{FAILED} cannot be started [Destroyed container cannot be restarted]

java.lang.IllegalStateException: Destroyed container cannot be restarted

                at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:95)

                at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)

                at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:171)

                at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:121)

                at org.eclipse.jetty.client.AbstractConnectorHttpClientTransport.doStart(AbstractConnectorHttpClientTransport.java:62)

                at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)

                at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:171)

                at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:121)

                at org.eclipse.jetty.client.HttpClient.doStart(HttpClient.java:225)

                at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)

                at com.unigone.telserver.gateway.MessagingGatewayFacebook.createHttpClient(MessagingGatewayFacebook.java:230)

                at com.unigone.telserver.gateway.MessagingGatewayFacebook.start(MessagingGatewayFacebook.java:121)

                at com.unigone.telserver.gateway.MessagingGateway.startGateway(MessagingGateway.java:381)

                at com.unigone.telserver.MainServer.startMessagingGateway(MainServer.java:1314)

                at com.unigone.telserver.admin.AdminServer.startGateway(AdminServer.java:4761)

                at com.unigone.telserver.admin.AdminServlet.handleRequest(AdminServlet.java:239)

                at com.unigone.telserver.admin.AdminServlet.doPost(AdminServlet.java:79)

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:523)

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)

                at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)

                at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:529)

                at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)

                at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1571)

                at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)

                at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1378)

                at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)

                at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)

                at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1544)

                at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)

                at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1300)

                at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)

                at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:51)

                at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:51)

                at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)

                at org.eclipse.jetty.server.Server.handle(Server.java:562)

                at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)

                at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)

                at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)

                at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)

                at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)

                at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)

                at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)

                at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:412)

                at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:381)

                at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:268)

                at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.lambda$new$0(AdaptiveExecutionStrategy.java:138)

                at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:407)

                at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)

                at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)

                at java.base/java.lang.Thread.run(Thread.java:834)

 

I may do something wrong but I don’t see where.

Thank you to give a help.

 

Bruno


Back to the top