From d4a0612015299d5912f152dcf018b4d1196bdb18 Mon Sep 17 00:00:00 2001 From: Dimitri Tenenbaum Date: Tue, 17 Oct 2023 09:21:37 +0200 Subject: [PATCH] Race condition (#5359) --- .../glassfish/jersey/client/HttpUrlConnectorProvider.java | 6 ++++-- .../glassfish/jersey/client/internal/HttpUrlConnector.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java b/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java index 25a6d78cf5..00ffd75411 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -283,7 +283,9 @@ public interface ConnectionFactory { * @throws java.io.IOException in case the connection cannot be provided. */ default HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException { - return (proxy == null) ? getConnection(url) : (HttpURLConnection) url.openConnection(proxy); + synchronized (this){ + return (proxy == null) ? getConnection(url) : (HttpURLConnection) url.openConnection(proxy); + } } } diff --git a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java index 1dbd9d8b1e..afea5f0bb8 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java @@ -311,7 +311,7 @@ protected void secureConnection(final JerseyClient client, final HttpURLConnecti if (DEFAULT_SSL_SOCKET_FACTORY.get() == suc.getSSLSocketFactory()) { // indicates that the custom socket factory was not set suc.setSSLSocketFactory(sslSocketFactory.get()); - } + } } }