Skip to content

Commit 4205110

Browse files
hughartkkyleh
andauthored
-added a counting semaphore to network client impl to avoid taking more connections that allowed and causing time skew errors (#582)
-incremented version Co-authored-by: kyleh <[email protected]>
1 parent 8d89b7b commit 4205110

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ plugins {
3535

3636
allprojects {
3737
group = 'com.spectralogic.ds3'
38-
version = '3.5.5'
38+
version = '3.5.6'
3939
}
4040

4141
subprojects {

ds3-sdk/src/main/java/com/spectralogic/ds3client/networking/NetworkClientImpl.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import java.security.cert.CertificateException;
6363
import java.security.cert.X509Certificate;
6464
import java.util.Map;
65+
import java.util.concurrent.Semaphore;
6566

6667
import static com.spectralogic.ds3client.utils.Signature.canonicalizeAmzHeaders;
6768
import static com.spectralogic.ds3client.utils.Signature.canonicalizeResource;
@@ -88,6 +89,7 @@ public class NetworkClientImpl implements NetworkClient {
8889

8990
final private CloseableHttpClient client;
9091
final private HttpHost host;
92+
final private Semaphore clientLock;
9193

9294
public NetworkClientImpl(final ConnectionDetails connectionDetails) {
9395
this(connectionDetails, createDefaultClient(connectionDetails));
@@ -100,6 +102,7 @@ public NetworkClientImpl(final ConnectionDetails connectionDetails, final Closea
100102
this.connectionDetails = connectionDetails;
101103
this.host = buildHost(connectionDetails);
102104
this.client = client;
105+
this.clientLock = new Semaphore(MAX_CONNECTION_PER_ROUTE);
103106
} catch (final MalformedURLException e) {
104107
throw new RuntimeException(e);
105108
}
@@ -236,11 +239,16 @@ public CloseableHttpResponse execute() throws IOException {
236239
}
237240

238241
final HttpRequest httpRequest = this.buildHttpRequest();
239-
this.addHeaders(httpRequest);
242+
clientLock.acquireUninterruptibly();
240243
try {
241-
return client.execute(this.host, httpRequest, this.getContext());
242-
} catch (final javax.net.ssl.SSLHandshakeException e) {
243-
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);
244+
this.addHeaders(httpRequest);
245+
try {
246+
return client.execute(this.host, httpRequest, this.getContext());
247+
} catch (final javax.net.ssl.SSLHandshakeException e) {
248+
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);
249+
}
250+
} finally {
251+
clientLock.release();
244252
}
245253
}
246254

0 commit comments

Comments
 (0)