Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit e4853b1

Browse files
authored
fix: make TransportChannel autocloseable (#212)
* fix: make TransportChannel autocloseable * fix: review changes
1 parent b635585 commit e4853b1

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/GrpcLoggingRpc.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,19 @@ public GrpcLoggingRpc(final LoggingOptions options) throws IOException {
100100
.usePlaintext()
101101
.executor(executor)
102102
.build();
103-
TransportChannel transportChannel = GrpcTransportChannel.create(managedChannel);
104-
clientContext =
105-
ClientContext.newBuilder()
106-
.setCredentials(null)
107-
.setExecutor(executor)
108-
.setTransportChannel(transportChannel)
109-
.setDefaultCallContext(GrpcCallContext.of(managedChannel, CallOptions.DEFAULT))
110-
.setBackgroundResources(
111-
Collections.<BackgroundResource>singletonList(transportChannel))
112-
.build();
103+
try (TransportChannel transportChannel = GrpcTransportChannel.create(managedChannel)) {
104+
clientContext =
105+
ClientContext.newBuilder()
106+
.setCredentials(null)
107+
.setExecutor(executor)
108+
.setTransportChannel(transportChannel)
109+
.setDefaultCallContext(GrpcCallContext.of(managedChannel, CallOptions.DEFAULT))
110+
.setBackgroundResources(
111+
Collections.<BackgroundResource>singletonList(transportChannel))
112+
.build();
113+
} catch (Exception ex) {
114+
throw new IOException(ex);
115+
}
113116
} else {
114117
LoggingSettingsBuilder settingsBuilder =
115118
new LoggingSettingsBuilder(LoggingSettings.newBuilder().build());

0 commit comments

Comments
 (0)