Skip to content

Commit d0ffb1e

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

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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
@@ -60,6 +60,7 @@
6060
import java.security.NoSuchAlgorithmException;
6161
import java.security.SignatureException;
6262
import java.util.Map;
63+
import java.util.concurrent.Semaphore;
6364

6465
import static com.spectralogic.ds3client.utils.Signature.canonicalizeAmzHeaders;
6566
import static com.spectralogic.ds3client.utils.Signature.canonicalizeResource;
@@ -86,6 +87,7 @@ public class NetworkClientImpl implements NetworkClient {
8687

8788
final private CloseableHttpClient client;
8889
final private HttpHost host;
90+
final private Semaphore clientLock;
8991

9092
public NetworkClientImpl(final ConnectionDetails connectionDetails) {
9193
this(connectionDetails, createDefaultClient(connectionDetails));
@@ -98,6 +100,7 @@ private NetworkClientImpl(final ConnectionDetails connectionDetails, final Close
98100
this.connectionDetails = connectionDetails;
99101
this.host = buildHost(connectionDetails);
100102
this.client = client;
103+
this.clientLock = new Semaphore(MAX_CONNECTION_PER_ROUTE);
101104
} catch (final MalformedURLException e) {
102105
throw new RuntimeException(e);
103106
}
@@ -229,11 +232,16 @@ CloseableHttpResponse execute() throws IOException {
229232
}
230233

231234
final HttpRequest httpRequest = this.buildHttpRequest();
232-
this.addHeaders(httpRequest);
235+
clientLock.acquireUninterruptibly();
233236
try {
234-
return client.execute(this.host, httpRequest, this.getContext());
235-
} catch (final javax.net.ssl.SSLHandshakeException e) {
236-
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);
237+
this.addHeaders(httpRequest);
238+
try {
239+
return client.execute(this.host, httpRequest, this.getContext());
240+
} catch (final javax.net.ssl.SSLHandshakeException e) {
241+
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);
242+
}
243+
} finally {
244+
clientLock.release();
237245
}
238246
}
239247

0 commit comments

Comments
 (0)