Skip to content

memory leak in RestClientBuilderImpl when creating RestClient from Builder with TLSRegistry #49871

@xumk

Description

@xumk

Describe the bug

I have code for create RestClient from QuarkusRestClientBuilder whit TLSConfiguration

QuarkusRestClientBuilder builder = QuarkusRestClientBuilder.newBuilder()
                .baseUri(new URI(baseUrl))
                .connectTimeout(timeout.toSeconds(), TimeUnit.SECONDS)
                .readTimeout(timeout.toSeconds(), TimeUnit.SECONDS);
        
        Instance<TlsConfigurationRegistry> tlsConfigurationRegistry = CDI.current().select(TlsConfigurationRegistry.class);
        if (tlsConfigurationRegistry.isResolvable()) {
            TlsConfiguration.from(tlsConfigurationRegistry.get(), Optional.ofNullable(tlsConfigurationName))
                    .ifPresent(builder::tlsConfiguration);
        }

        restApi = builder.build(MyRestApi.class);

I am creating multiple instances in one application. when i clears the link restApi after use. I expect the client to delete GC, but this is not happening.

i see quarkus code and RestClientBuilderImpl always add client in tlsConfigNameToVertxHttpClients in RestClientRecorder

TlsConfig tlsConfig = clientBuilder.getTlsConfig();
        if (tlsConfig != null && tlsConfig.getName().isPresent()) {
            RestClientRecorder.registerReloadableHttpClient(tlsConfig.getName().get(), clientImpl.getVertxHttpClient());
        }
...
public static void registerReloadableHttpClient(String tlsConfigName, HttpClient httpClient) {
        tlsConfigNameToVertxHttpClients.computeIfAbsent(tlsConfigName, new Function<>() {
            @Override
            public List<HttpClient> apply(String s) {
                return new ArrayList<>(1);
            }
        }).add(httpClient);
    }

but tlsConfigNameToVertxHttpClients cleared only by ShutdownContext event

Expected behavior

from tlsConfigNameToVertxHttpClients deletes link on client and GC cleared object

Actual behavior

i see log

2025-08-31 14:12:04 INFO [io.qu.re.cl.re.CertificateUpdateEventListener]] (vert.x-eventloop-thread-0) Certificate reloaded for the REST client(s) using the TLS configuration (bucket) name 'myclient'
2025-08-31 14:12:04 INFO [io.qu.re.cl.re.CertificateUpdateEventListener]] (vert.x-eventloop-thread-0) Certificate reloaded for the REST client(s) using the TLS configuration (bucket) name 'myclient'
2025-08-31 14:12:04 INFO [io.qu.re.cl.re.CertificateUpdateEventListener]] (vert.x-eventloop-thread-0) Certificate reloaded for the REST client(s) using the TLS configuration (bucket) name 'myclient'

from tlsConfigNameToVertxHttpClients not deletes link on client nd GC not cleared object

tls re-reading is triggered several.

How to Reproduce?

No response

Output of uname -a or ver

Darwin cab-wsm-0279148 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:28:17 PDT 2025; root:xnu-11417.140.69~1/RELEASE_X86_64 x86_64

Output of java -version

openjdk version "21.0.2" 2024-01-16

Quarkus version or git rev

3.20.2.2

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.6

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions