From da595b7ac4bec05f32a12c853bb62a89820ab1ae Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Tue, 21 Jul 2026 16:03:37 -0400 Subject: [PATCH] Close Demo2 client before exit --- .../com/scylladb/alternator/demo/Demo2.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/demo/java/com/scylladb/alternator/demo/Demo2.java b/src/demo/java/com/scylladb/alternator/demo/Demo2.java index f823cf8..8601db7 100644 --- a/src/demo/java/com/scylladb/alternator/demo/Demo2.java +++ b/src/demo/java/com/scylladb/alternator/demo/Demo2.java @@ -160,21 +160,19 @@ public static void main(String[] args) { ddb = getTraditionalClient(URI.create(endpoint), myCredentials); } - // run DescribeEndpoints several times - for (int i = 0; i < 10; i++) { - DescribeEndpointsRequest request = DescribeEndpointsRequest.builder().build(); - DescribeEndpointsResponse response = ddb.describeEndpoints(request); - System.out.println(response); + try { + // run DescribeEndpoints several times + for (int i = 0; i < 10; i++) { + DescribeEndpointsRequest request = DescribeEndpointsRequest.builder().build(); + DescribeEndpointsResponse response = ddb.describeEndpoints(request); + System.out.println(response); + } + } finally { + ddb.close(); } - // FIXME: The AWS SDK leaves behind an IdleConnectionReaper thread, - // which causes mvn to hang waiting for it to shut down (which it - // won't). Perhaps if we hold the HttpClient object and close() it, - // it will get rid of this reaper object. - // https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/core/client/builder/SdkSyncClientBuilder.html#httpClient-software.amazon.awssdk.http.SdkHttpClient- - // explains that with httpClient(), "This client must be closed by the - // user when it is ready to be disposed. The SDK will not close the - // HTTP client when the service client is closed." Maybe we should - // use httpClientBuilder() instead, which doesn't have this problem? + + System.out.println("Done"); + System.exit(0); } // A hack to disable SSL certificate checks. Useful when running with