Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.grpc.CallOptions;
import io.grpc.ClientInterceptor;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.MethodDescriptor;
import java.time.Duration;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -190,28 +189,30 @@ private ChannelPool newChannelPoolFromProvider(
private ChannelPool newChannelPoolFromProvider(
ChannelProvider channelProvider, String logName, ClientInterceptor... interceptors) {
if (channelProvider.isSingleEndpoint()) {
return new SingleChannelPool(
channelBuilderToSupplier(channelProvider.newChannelBuilder(), interceptors));
return new SingleChannelPool(channelSupplier(channelProvider, interceptors));
}

if (logName != null) {
return new ChannelPoolDpImpl(
channelBuilderToSupplier(channelProvider.newChannelBuilder(), interceptors),
channelSupplier(channelProvider, interceptors),
currentConfiguration,
logName,
metrics.getDebugTagTracer(),
backgroundExecutor);
}

return new ChannelPoolDpImpl(
channelBuilderToSupplier(channelProvider.newChannelBuilder(), interceptors),
channelSupplier(channelProvider, interceptors),
currentConfiguration,
metrics.getDebugTagTracer(),
backgroundExecutor);
}

private Supplier<ManagedChannel> channelBuilderToSupplier(
ManagedChannelBuilder<?> channelBuilder, ClientInterceptor... interceptors) {
return () -> channelBuilder.intercept(interceptors).build();
// Each supplier invocation must produce a fresh ManagedChannelBuilder. Capturing one builder
// and calling .build() on it repeatedly lets anything that mutates the builder between builds
// accumulate — the Nth channel then ships with N copies of that interceptor.
private Supplier<ManagedChannel> channelSupplier(
ChannelProvider channelProvider, ClientInterceptor... interceptors) {
return () -> channelProvider.newChannelBuilder().intercept(interceptors).build();
}
}
Loading
Loading