aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2016-10-25 15:04:41 -0700
committerGravatar Muxi Yan <mxyan@google.com>2016-10-25 15:04:41 -0700
commit6f5cfedfd56caddc1f1e99b9341c771d03f15b11 (patch)
tree97c97bbbd685a9d84903598c3f84358fbdbb0829 /src/objective-c
parent4f6a19b292ee90ede7a074352d9c73640f73a450 (diff)
Add comments for GRPCHost
Diffstat (limited to 'src/objective-c')
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.m6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m
index 4737e45168..c41cb81ee1 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.m
+++ b/src/objective-c/GRPCClient/private/GRPCHost.m
@@ -54,6 +54,10 @@ NS_ASSUME_NONNULL_BEGIN
#define GRPC_OBJC_VERSION_STRING @"1.0.0"
static NSMutableDictionary *kHostCache;
+
+// This connectivity monitor flushes the host cache when connectivity status
+// changes. Otherwise, a new call might still use the cached channel which is
+// no longer available and will call gRPC to hang
static GRPCConnectivityMonitor *connectivityMonitor = nil;
@implementation GRPCHost {
@@ -94,6 +98,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
dispatch_once(&cacheInitialization, ^{
kHostCache = [NSMutableDictionary dictionary];
});
+
@synchronized(kHostCache) {
GRPCHost *cachedHost = kHostCache[address];
if (cachedHost) {
@@ -106,6 +111,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
kHostCache[address] = self;
}
// Keep a single monitor to flush the cache if the connectivity status changed
+ // Thread safety guarded by @synchronized(kHostCache)
if (!connectivityMonitor) {
connectivityMonitor =
[GRPCConnectivityMonitor monitorWithHost:hostURL.host];