Fix refcounting issue

pull/16213/head
Muxi Yan 6 years ago
parent 92fd2620ab
commit 5c275b5f22
  1. 16
      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

Loading…
Cancel
Save