Hello,
I am adding some information to my previous post. Setting the Jetty logs
gives an information that the HTTP11 is not destroyed but reused :
!!! starting the HttpClient:
2022-07-29 14:52:55,595 [TelServerDbProcess] DEBUG ContainerLifeCycle -
ClientConnector@3d58709c{STOPPED} added
{org.eclipse.jetty.io.ClientConnector$Configurator@2b74873e,POJO}
2022-07-29 14:52:55,595 [TelServerDbProcess] DEBUG ContainerLifeCycle -
ClientConnector@3d58709c{STOPPED} added
{Client@30d07b39[provider=null,keyStore=null,trustStore=null],AUTO}
2022-07-29 14:52:55,597 [TelServerDbProcess] DEBUG ContainerLifeCycle -
HttpClientTransportDynamic@7dbb9284{STOPPED} added
{ClientConnector@3d58709c{STOPPED},AUTO}
!!! the HTTP11 instance is HTTP11@7a0f244f
2022-07-29 14:52:55,606 [TelServerDbProcess] DEBUG ContainerLifeCycle -
HttpClientTransportDynamic@7dbb9284{STOPPED} added
{HTTP11@7a0f244f[http/1.1],AUTO}
2022-07-29 14:52:55,606 [TelServerDbProcess] DEBUG ContainerLifeCycle -
HttpClient@1ae8ca52{STOPPED} added
{HttpClientTransportDynamic@7dbb9284{STOPPED},AUTO}
...
2022-07-29 14:52:55,617 [TelServerDbProcess] DEBUG AbstractLifeCycle -
STARTED @9840ms HttpClientTransportDynamic@7dbb9284{STARTED}
!!! now stopping the HttpClient:
...
2022-07-29 14:53:08,248 [qtp1500697171-21] DEBUG AbstractLifeCycle -
STOPPING HttpClient@1ae8ca52{STARTED}
2022-07-29 14:53:08,249 [qtp1500697171-21] DEBUG AbstractLifeCycle -
STOPPING HttpClientTransportDynamic@7dbb9284{STARTED}
2022-07-29 14:53:08,249 [qtp1500697171-21] DEBUG AbstractLifeCycle -
STOPPING HTTP11@7a0f244f[http/1.1]
2022-07-29 14:53:08,249 [qtp1500697171-21] DEBUG AbstractLifeCycle - STOPPED
HTTP11@7a0f244f[http/1.1]
!!! the HTTP11@7a0f244f seems to be stopped !
2022-07-29 14:53:08,249 [qtp1500697171-21] DEBUG AbstractLifeCycle -
STOPPING ClientConnector@3d58709c{STARTED}
2022-07-29 14:53:08,249 [qtp1500697171-21] DEBUG AbstractLifeCycle -
STOPPING ClientSelectorManager@555af5fd{STARTED}
2022-07-29 14:53:08,249 [qtp1500697171-21] DEBUG AbstractLifeCycle -
STOPPING ManagedSelector@26e96571{STARTED} id=0 keys=0 selected=0 updates=0
...
!!! starting the HttpClient (a new one)
...
2022-07-29 14:53:14,862 [qtp1500697171-23] DEBUG ContainerLifeCycle -
HttpClientTransportDynamic@2a56fc9c{STOPPED} added
{ClientConnector@1e62f940{STOPPED},AUTO}
!!! adding the same HTTP11 instance
2022-07-29 14:53:14,862 [qtp1500697171-23] DEBUG ContainerLifeCycle -
HttpClientTransportDynamic@2a56fc9c{STOPPED} added
{HTTP11@7a0f244f[http/1.1],AUTO}
2022-07-29 14:53:14,862 [qtp1500697171-23] DEBUG ContainerLifeCycle -
HttpClient@23f7b86f{STOPPED} added
{HttpClientTransportDynamic@2a56fc9c{STOPPED},AUTO}
2022-07-29 14:53:14,862 [qtp1500697171-23] DEBUG ContainerLifeCycle -
HttpClient@23f7b86f{STOPPED} added
{org.eclipse.jetty.client.ProtocolHandlers@183949c1,POJO}
2022-07-29 14:53:14,862 [qtp1500697171-23] DEBUG ContainerLifeCycle -
HttpClient@23f7b86f{STOPPED} added
{org.eclipse.jetty.client.HttpClient$ContentDecoderFactorySet@73022036,POJO}
2022-07-29 14:53:14,862 [qtp1500697171-23] DEBUG AbstractLifeCycle -
STARTING HttpClient@23f7b86f{STOPPED}
...
2022-07-29 14:53:14,881 [HttpClient@23f7b86f-245] DEBUG ManagedSelector -
updateable 1
2022-07-29 14:53:14,881 [HttpClient@23f7b86f-245] DEBUG ManagedSelector -
update org.eclipse.jetty.io.ManagedSelector$Start@ec37c77
2022-07-29 14:53:14,881 [qtp1500697171-23] DEBUG AbstractLifeCycle - STARTED
@29104ms ManagedSelector@467a850e{STARTED} id=0 keys=0 selected=0 updates=0
2022-07-29 14:53:14,881 [qtp1500697171-23] DEBUG AbstractLifeCycle - STARTED
@29104ms ClientSelectorManager@39708578{STARTED}
2022-07-29 14:53:14,881 [qtp1500697171-23] DEBUG AbstractLifeCycle - STARTED
@29104ms ClientConnector@1e62f940{STARTED}
2022-07-29 14:53:14,881 [qtp1500697171-23] DEBUG AbstractLifeCycle -
STARTING HTTP11@7a0f244f[http/1.1]
2022-07-29 14:53:14,882 [qtp1500697171-23] WARN AbstractLifeCycle - FAILED
HTTP11@7a0f244f[http/1.1]: java.lang.IllegalStateException: Destroyed
container cannot be restarted
I dont understand why it reuses the same instance for a new HttpClient but
I suspect that something may be wrong in my usage. When I create a
HttpClient I create the factory and the HttpClientTransportDynamic. Is it
the right way to do ?
SslContextFactory.Client
sslContextFactory = new SslContextFactory.Client(true);
ClientConnector
clientConnector = new ClientConnector();
clientConnector.setSslContextFactory(sslContextFactory);
httpClient = new
HttpClient(new HttpClientTransportDynamic(clientConnector));
httpClient.start();
Thanks for your help.
Bruno
De : jetty-users [mailto:[email protected]] De la part de
Bruno Konik
Envoyé : jeudi 28 juillet 2022 16:49
À : [email protected]
Objet : [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(ContainerLifeCyc
le.java:95)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.j
ava:93)
at
org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle
.java:171)
at
org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCyc
le.java:121)
at
org.eclipse.jetty.client.AbstractConnectorHttpClientTransport.doStart(Abstra
ctConnectorHttpClientTransport.java:62)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.j
ava:93)
at
org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle
.java:171)
at
org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCyc
le.java:121)
at
org.eclipse.jetty.client.HttpClient.doStart(HttpClient.java:225)
at
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.j
ava:93)
at
com.unigone.telserver.gateway.MessagingGatewayFacebook.createHttpClient(Mess
agingGatewayFacebook.java:230)
at
com.unigone.telserver.gateway.MessagingGatewayFacebook.start(MessagingGatewa
yFacebook.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:1
22)
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(AbstractConne
ction.java:319)
at
org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
at
org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoi
nt.java:53)
at
org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(Ada
ptiveExecutionStrategy.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(Rese
rvedThreadExecutor.java:407)
at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:
894)
at
org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.j
ava:1038)
at java.base/java.lang.Thread.run(Thread.java:834)
I may do something wrong but I dont see where.
Thank you to give a help.
Bruno
_______________________________________________
jetty-users mailing list
[email protected]
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users