diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index a91949684c4..2420988f427 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -204,7 +204,7 @@ NSTimeInterval kChannelDestroyDelay = 30; if (self->_unmanagedChannel) { grpc_channel_destroy(self->_unmanagedChannel); self->_unmanagedChannel = nil; - [gChannelPool removeChannelWithConfiguration:self->_configuration]; + [gChannelPool removeChannel:self]; } }); } diff --git a/src/objective-c/GRPCClient/private/GRPCChannelPool.h b/src/objective-c/GRPCClient/private/GRPCChannelPool.h index bd1350c15d2..e9c2ef2bd14 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannelPool.h +++ b/src/objective-c/GRPCClient/private/GRPCChannelPool.h @@ -55,8 +55,8 @@ NS_ASSUME_NONNULL_BEGIN */ - (GRPCChannel *)channelWithConfiguration:(GRPCChannelConfiguration *)configuration; -/** Remove a channel with particular configuration. */ -- (void)removeChannelWithConfiguration:(GRPCChannelConfiguration *)configuration; +/** Remove a channel from the pool. */ +- (void)removeChannel:(GRPCChannel *)channel; /** Clear all channels in the pool. */ - (void)removeAllChannels; diff --git a/src/objective-c/GRPCClient/private/GRPCChannelPool.m b/src/objective-c/GRPCClient/private/GRPCChannelPool.m index bfc624eb4ea..b5b3ff60efa 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannelPool.m +++ b/src/objective-c/GRPCClient/private/GRPCChannelPool.m @@ -199,9 +199,13 @@ extern const char *kCFStreamVarName; return channel; } -- (void)removeChannelWithConfiguration:(GRPCChannelConfiguration *)configuration { +- (void)removeChannel:(GRPCChannel *)channel { @synchronized(self) { - [self->_channelPool removeObjectForKey:configuration]; + [_channelPool enumerateKeysAndObjectsUsingBlock:^(GRPCChannelConfiguration * _Nonnull key, GRPCChannel * _Nonnull obj, BOOL * _Nonnull stop) { + if (obj == channel) { + [self->_channelPool removeObjectForKey:key]; + } + }]; } } diff --git a/src/objective-c/tests/ChannelTests/ChannelPoolTest.m b/src/objective-c/tests/ChannelTests/ChannelPoolTest.m index b195b747a12..db64ac6339e 100644 --- a/src/objective-c/tests/ChannelTests/ChannelPoolTest.m +++ b/src/objective-c/tests/ChannelTests/ChannelPoolTest.m @@ -59,7 +59,7 @@ NSString *kDummyHost = @"dummy.host"; GRPCChannelPool *pool = [[GRPCChannelPool alloc] init]; GRPCChannel *channel1 = [pool channelWithConfiguration:config1]; - [pool removeChannelWithConfiguration:config1]; + [pool removeChannel:channel1]; GRPCChannel *channel2 = [pool channelWithConfiguration:config1]; XCTAssertNotEqual(channel1, channel2);