aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-08-01 10:51:14 -0700
committerGravatar Muxi Yan <mxyan@google.com>2018-08-01 10:51:14 -0700
commit5c275b5f227a725db7e58da89a7ae7a1c286cde8 (patch)
tree175ad20167269df1310cb17aa17c14a1ca4d2935 /src/objective-c
parent92fd2620ab03c438fdeab23400cb6f31f5ba7816 (diff)
Fix refcounting issue
Diffstat (limited to 'src/objective-c')
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.m16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m
index 9783b06440..387a88dc17 100644
--- a/src/objective-c/GRPCClient/GRPCCall.m
+++ b/src/objective-c/GRPCClient/GRPCCall.m
@@ -220,17 +220,17 @@ static NSString *const kBearerPrefix = @"Bearer ";
}
- (void)cancel {
+ if (!self.isWaitingForToken) {
+ [self cancelCall];
+ } else {
+ self.isWaitingForToken = NO;
+ }
[self
maybeFinishWithError:[NSError
errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeCancelled
userInfo:@{NSLocalizedDescriptionKey : @"Canceled by app"}]];
- if (!self.isWaitingForToken) {
- [self cancelCall];
- } else {
- self.isWaitingForToken = NO;
- }
}
- (void)maybeFinishWithError:(NSError *)errorOrNil {
@@ -292,6 +292,7 @@ static NSString *const kBearerPrefix = @"Bearer ";
// don't want to throw, because the app shouldn't crash for a behavior
// that's on the hands of any server to have. Instead we finish and ask
// the server to cancel.
+ [strongSelf cancelCall];
[strongSelf
maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeResourceExhausted
@@ -300,7 +301,6 @@ static NSString *const kBearerPrefix = @"Bearer ";
@"Client does not have enough memory to "
@"hold the server response."
}]];
- [strongSelf cancelCall];
return;
}
[strongWriteable enqueueValue:data
@@ -530,13 +530,13 @@ static NSString *const kBearerPrefix = @"Bearer ";
}
- (void)connectivityChanged:(NSNotification *)note {
+ // Cancel underlying call upon this notification
+ [self cancelCall];
[self maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeUnavailable
userInfo:@{
NSLocalizedDescriptionKey : @"Connectivity lost."
}]];
- // Cancel underlying call upon this notification
- [self cancelCall];
}
@end