Skip to content

Commit a0adaf5

Browse files
committed
fix(sdk): Share OkHttpClient instance to prevent resource leaks
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
1 parent 2854272 commit a0adaf5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

sdk/src/main/java/io/opentdf/platform/sdk/SDKBuilder.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public SDKBuilder protocol(ProtocolType protocolType) {
177177
return this;
178178
}
179179

180-
private Interceptor getAuthInterceptor(RSAKey rsaKey) {
180+
private Interceptor getAuthInterceptor(RSAKey rsaKey, OkHttpClient httpClient) {
181181
if (platformEndpoint == null) {
182182
throw new SDKException("cannot build an SDK without specifying the platform endpoint");
183183
}
@@ -191,7 +191,6 @@ private Interceptor getAuthInterceptor(RSAKey rsaKey) {
191191
// we don't add the auth listener to this channel since it is only used to call
192192
// the well known endpoint
193193
GetWellKnownConfigurationResponse config;
194-
var httpClient = getHttpClient();
195194
ProtocolClient bootstrapClient = getUnauthenticatedProtocolClient(platformEndpoint, httpClient) ;
196195
var stub = new WellKnownServiceClient(bootstrapClient);
197196
try {
@@ -266,9 +265,9 @@ ServicesAndInternals buildServices() {
266265
}
267266

268267
this.platformEndpoint = AddressNormalizer.normalizeAddress(this.platformEndpoint, this.usePlainText);
269-
var authInterceptor = getAuthInterceptor(dpopKey);
270-
var kasClient = getKASClient(dpopKey, authInterceptor);
271268
var httpClient = getHttpClient();
269+
var authInterceptor = getAuthInterceptor(dpopKey, httpClient);
270+
var kasClient = getKASClient(dpopKey, authInterceptor, httpClient);
272271
var client = getProtocolClient(platformEndpoint, httpClient, authInterceptor);
273272
var attributeService = new AttributesServiceClient(client);
274273
var namespaceService = new NamespaceServiceClient(client);
@@ -341,9 +340,9 @@ public SDK.KAS kas() {
341340
}
342341

343342
@Nonnull
344-
private KASClient getKASClient(RSAKey dpopKey, Interceptor interceptor) {
343+
private KASClient getKASClient(RSAKey dpopKey, Interceptor interceptor, OkHttpClient httpClient) {
345344
BiFunction<OkHttpClient, String, ProtocolClient> protocolClientFactory = (OkHttpClient client, String address) -> getProtocolClient(address, client, interceptor);
346-
return new KASClient(getHttpClient(), protocolClientFactory, dpopKey, usePlainText);
345+
return new KASClient(httpClient, protocolClientFactory, dpopKey, usePlainText);
347346
}
348347

349348
public SDK build() {

0 commit comments

Comments
 (0)