Skip to content

Using Jetty with Spring Webclient causes thread leak #22

@thomas-br

Description

@thomas-br

Hi,

I am currently looking into using the jetty httpclient to replace netty for my Spring Webclient which is responsible for external calls. As there is a hard limit when these external requests shall be cancelled, I am using a timeout in the Webclient execution call:

ResponseEntity<String> response = request.retrieve()
    .toEntity(String.class)
    .timeout(Duration.ofMillis(timeoutMillis))
    .block();

I am using Jetty as ClientHttpConnector, simplified:

HttpClient httpClient = new HttpClient(SSL_CONTEXT_FACTORY);
WebClient.builder()
    .clientConnector(new JettyClientHttpConnector(httpClient))
...

In a load test scenario where all calls are cancelled before it can finish, I am observing a thread leak on the Jetty HttpClient Threads:
image
Even after a long cooldown they are not coming back. And at the peak new requests are failing due to no free resources.

Caused by: java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
	at java.base/java.lang.Thread.start0(Native Method)
	at java.base/java.lang.Thread.start(Thread.java:804)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.startThread(QueuedThreadPool.java:660)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions