From ece33c9daaae5b8ef937bfb4f14901df397af51e Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Fri, 13 Mar 2026 14:12:38 -0500 Subject: [PATCH 1/2] Make ClientTransport extend Closeable ClientTransport now extends Closeable with a default no-op close() implementation. This allows transports that manage resources (connection pools, HTTP clients, etc.) to be properly closed when no longer needed, without breaking existing implementations. --- .../smithy/java/client/core/ClientTransport.java | 12 +++++++++++- .../java/client/http/JavaHttpClientTransport.java | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientTransport.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientTransport.java index 7cf520f36..30bd1cfa2 100644 --- a/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientTransport.java +++ b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/ClientTransport.java @@ -5,6 +5,8 @@ package software.amazon.smithy.java.client.core; +import java.io.Closeable; +import java.io.IOException; import java.net.ConnectException; import java.net.ProtocolException; import java.net.SocketException; @@ -25,7 +27,7 @@ * @implNote To be discoverable by dynamic clients and client code generators, * ClientTransport's should implement a {@link ClientTransportFactory} service provider. */ -public interface ClientTransport { +public interface ClientTransport extends Closeable { /** * Send a prepared request. * @@ -46,6 +48,14 @@ public interface ClientTransport { */ MessageExchange messageExchange(); + /** + * {@inheritDoc} + * + *

Default implementation is a no-op. + */ + @Override + default void close() throws IOException {} + /** * Remaps a thrown exception to an appropriate {@link TransportException} or {@link CallException}. * diff --git a/client/client-http/src/main/java/software/amazon/smithy/java/client/http/JavaHttpClientTransport.java b/client/client-http/src/main/java/software/amazon/smithy/java/client/http/JavaHttpClientTransport.java index 4713a7087..c93e00f66 100644 --- a/client/client-http/src/main/java/software/amazon/smithy/java/client/http/JavaHttpClientTransport.java +++ b/client/client-http/src/main/java/software/amazon/smithy/java/client/http/JavaHttpClientTransport.java @@ -207,6 +207,11 @@ private static HttpVersion javaToSmithyVersion(HttpClient.Version version) { }; } + @Override + public void close() { + client.close(); + } + public static final class Factory implements ClientTransportFactory { @Override public String name() { From 4a0efd47761d87b56491fabfc5d8b650bb6696d9 Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Fri, 13 Mar 2026 14:26:40 -0500 Subject: [PATCH 2/2] Make Client implement Closeable Client.close() delegates to the transport's close() method, enabling try-with-resources usage and proper cleanup of transport resources like connection pools. --- .../amazon/smithy/java/client/core/Client.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/client/client-api/src/main/java/software/amazon/smithy/java/client/core/Client.java b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/Client.java index 1dc652157..78e70772a 100644 --- a/client/client-api/src/main/java/software/amazon/smithy/java/client/core/Client.java +++ b/client/client-api/src/main/java/software/amazon/smithy/java/client/core/Client.java @@ -5,6 +5,9 @@ package software.amazon.smithy.java.client.core; +import java.io.Closeable; +import java.io.IOException; +import java.io.UncheckedIOException; import java.util.List; import java.util.concurrent.CompletionException; import java.util.function.Predicate; @@ -29,7 +32,7 @@ /** * Base Smithy client class. */ -public abstract class Client { +public abstract class Client implements Closeable { private final ClientConfig config; private final ClientPipeline pipeline; @@ -130,6 +133,18 @@ public ClientConfig config() { return config; } + /** + * Closes the transport used by this client. + */ + @Override + public void close() { + try { + config.transport().close(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + /** * Builder for Clients and request overrides. *