Skip to content

Commit 48795fa

Browse files
committed
Fix connection pool shutdown by reusing cached SSL connections
Use computeIfAbsent() instead of compute() to prevent creating a new PoolingHttpClientConnectionManager on every createClient() call. This fixes "Connection pool shut down" exceptions that occurred when multiple HttpClients shared a connection manager that was inadvertently replaced.
1 parent c9061a3 commit 48795fa

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

token-client/src/main/java/com/sap/cloud/security/client/DefaultHttpClientFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public CloseableHttpClient createClient(ClientIdentity clientIdentity) throws Ht
5656
HttpClientBuilder httpClientBuilder = HttpClients.custom().setDefaultRequestConfig(requestConfig);
5757

5858
if (clientId != null && clientIdentity.isCertificateBased()) {
59-
SslConnection connectionPool = sslConnectionPool.compute(clientId,
60-
(s, c) -> new SslConnection(clientIdentity));
59+
SslConnection connectionPool = sslConnectionPool.computeIfAbsent(clientId,
60+
s -> new SslConnection(clientIdentity));
6161
return httpClientBuilder
6262
.setConnectionManager(connectionPool.poolingConnectionManager)
6363
.setSSLContext(connectionPool.context)

0 commit comments

Comments
 (0)