|
29 | 29 | import io.grpc.CallOptions; |
30 | 30 | import io.grpc.ClientInterceptor; |
31 | 31 | import io.grpc.ManagedChannel; |
32 | | -import io.grpc.ManagedChannelBuilder; |
33 | 32 | import io.grpc.MethodDescriptor; |
34 | 33 | import java.time.Duration; |
35 | 34 | import java.util.concurrent.ScheduledExecutorService; |
@@ -190,28 +189,30 @@ private ChannelPool newChannelPoolFromProvider( |
190 | 189 | private ChannelPool newChannelPoolFromProvider( |
191 | 190 | ChannelProvider channelProvider, String logName, ClientInterceptor... interceptors) { |
192 | 191 | if (channelProvider.isSingleEndpoint()) { |
193 | | - return new SingleChannelPool( |
194 | | - channelBuilderToSupplier(channelProvider.newChannelBuilder(), interceptors)); |
| 192 | + return new SingleChannelPool(channelSupplier(channelProvider, interceptors)); |
195 | 193 | } |
196 | 194 |
|
197 | 195 | if (logName != null) { |
198 | 196 | return new ChannelPoolDpImpl( |
199 | | - channelBuilderToSupplier(channelProvider.newChannelBuilder(), interceptors), |
| 197 | + channelSupplier(channelProvider, interceptors), |
200 | 198 | currentConfiguration, |
201 | 199 | logName, |
202 | 200 | metrics.getDebugTagTracer(), |
203 | 201 | backgroundExecutor); |
204 | 202 | } |
205 | 203 |
|
206 | 204 | return new ChannelPoolDpImpl( |
207 | | - channelBuilderToSupplier(channelProvider.newChannelBuilder(), interceptors), |
| 205 | + channelSupplier(channelProvider, interceptors), |
208 | 206 | currentConfiguration, |
209 | 207 | metrics.getDebugTagTracer(), |
210 | 208 | backgroundExecutor); |
211 | 209 | } |
212 | 210 |
|
213 | | - private Supplier<ManagedChannel> channelBuilderToSupplier( |
214 | | - ManagedChannelBuilder<?> channelBuilder, ClientInterceptor... interceptors) { |
215 | | - return () -> channelBuilder.intercept(interceptors).build(); |
| 211 | + // Each supplier invocation must produce a fresh ManagedChannelBuilder. Capturing one builder |
| 212 | + // and calling .build() on it repeatedly lets anything that mutates the builder between builds |
| 213 | + // accumulate — the Nth channel then ships with N copies of that interceptor. |
| 214 | + private Supplier<ManagedChannel> channelSupplier( |
| 215 | + ChannelProvider channelProvider, ClientInterceptor... interceptors) { |
| 216 | + return () -> channelProvider.newChannelBuilder().intercept(interceptors).build(); |
216 | 217 | } |
217 | 218 | } |
0 commit comments