From e191ca4a0cbd4ed47ecbe4da1cd53d2753c3534a Mon Sep 17 00:00:00 2001 From: kyleh Date: Wed, 7 Oct 2020 15:21:10 -0500 Subject: [PATCH] -added a counting semaphore to network client impl to avoid taking more connections that allowed and causing time skew errors -incremented version --- build.gradle | 2 +- .../ds3client/networking/NetworkClientImpl.java | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index a8d549d9a..e4ed109e0 100644 --- a/build.gradle +++ b/build.gradle @@ -35,7 +35,7 @@ plugins { allprojects { group = 'com.spectralogic.ds3' - version = '3.5.5' + version = '3.5.6' } subprojects { diff --git a/ds3-sdk/src/main/java/com/spectralogic/ds3client/networking/NetworkClientImpl.java b/ds3-sdk/src/main/java/com/spectralogic/ds3client/networking/NetworkClientImpl.java index 755ddd6ee..25c16195d 100644 --- a/ds3-sdk/src/main/java/com/spectralogic/ds3client/networking/NetworkClientImpl.java +++ b/ds3-sdk/src/main/java/com/spectralogic/ds3client/networking/NetworkClientImpl.java @@ -62,6 +62,7 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.Map; +import java.util.concurrent.Semaphore; import static com.spectralogic.ds3client.utils.Signature.canonicalizeAmzHeaders; import static com.spectralogic.ds3client.utils.Signature.canonicalizeResource; @@ -88,6 +89,7 @@ public class NetworkClientImpl implements NetworkClient { final private CloseableHttpClient client; final private HttpHost host; + final private Semaphore clientLock; public NetworkClientImpl(final ConnectionDetails connectionDetails) { this(connectionDetails, createDefaultClient(connectionDetails)); @@ -100,6 +102,7 @@ public NetworkClientImpl(final ConnectionDetails connectionDetails, final Closea this.connectionDetails = connectionDetails; this.host = buildHost(connectionDetails); this.client = client; + this.clientLock = new Semaphore(MAX_CONNECTION_PER_ROUTE); } catch (final MalformedURLException e) { throw new RuntimeException(e); } @@ -236,11 +239,16 @@ public CloseableHttpResponse execute() throws IOException { } final HttpRequest httpRequest = this.buildHttpRequest(); - this.addHeaders(httpRequest); + clientLock.acquireUninterruptibly(); try { - return client.execute(this.host, httpRequest, this.getContext()); - } catch (final javax.net.ssl.SSLHandshakeException e) { - throw new InvalidCertificate("The certificate on black pearl is not a strong certificate and the request is being aborted. Configure with the insecure option to perform the request.", e); + this.addHeaders(httpRequest); + try { + return client.execute(this.host, httpRequest, this.getContext()); + } catch (final javax.net.ssl.SSLHandshakeException e) { + throw new InvalidCertificate("The certificate on black pearl is not a strong certificate and the request is being aborted. Configure with the insecure option to perform the request.", e); + } + } finally { + clientLock.release(); } }