On Tue, 2023-09-19 at 18:31 +0200, Damien Urruty wrote: > Hello, > > We are using Apache HttpClient 5.2.1 to connect to potentially > different > servers, and for each of them, we can have a mix of "classic" HTTP > requests > and long connections to receive Server-Sent Events. In some cases, we > have > to cancel those long requests and reopen them later. > > Today we use a single client instance for all requests, that is > configured like > this > < > https://github.com/SonarSource/sonarlint-core/blob/9.2.0.74516/http/sr > c/main/java/org/sonarsource/sonarlint/core/http/HttpClientProvider.ja > va#L91>. > SSE connections are opened here > < > https://github.com/SonarSource/sonarlint-core/blob/9.2.0.74516/http/sr > c/main/java/org/sonarsource/sonarlint/core/http/ApacheHttpClientAdapt > er.java#L105> > and canceled here > < > https://github.com/SonarSource/sonarlint-core/blob/9.2.0.74516/http/sr > c/main/java/org/sonarsource/sonarlint/core/http/ApacheHttpClientAdapt > er.java#L250> > . > > We recently noticed that after canceling SSE connections, we were > still > receiving events from the server. We made some assumptions: > > * canceling the Future returned by CloseableAsyncHttpClient.execute() > does > not close the connection, so we keep receiving events > * This might be caused by the connection manager, who retains the > connection > > Are our assumptions right? Can we configure the connection manager to > close > and not reuse those connections used for SSE? Or would we have to use > separate clients? > > One thing that we noticed when we investigated is that in rare cases, > the > connection would close and wouldn't be reused. In this scenario, we > can see > an InterruptedException in the logs, triggered from this line > < > https://github.com/apache/httpcomponents-client/blob/master/httpclient > 5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainCl > ientExec.java#L137>. > Is there something we are not doing correctly? >
Hi Damien I could not spot anything obviously wrong right away. I will take a closer look at it again in the coming days. In meantime it would help a great deal if you could produce a context / wire log of the session that works correctly and another one that does not. I also promise to review the relevant bits of connection management code to see if there are any defects. Oleg --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org