|
44 | 44 | // Sends the bundle ID. Refer to b/130301479 for details.
|
45 | 45 | static NSString *const kiOSBundleIdentifierHeaderName =
|
46 | 46 | @"X-Ios-Bundle-Identifier"; ///< HTTP Header Field Name
|
| 47 | + |
| 48 | +/// Retryable HTTP status code. |
| 49 | +static NSInteger const kRCNFetchResponseHTTPStatusOk = 200; |
| 50 | +static NSInteger const kRCNFetchResponseHTTPStatusClientTimeout = 429; |
| 51 | +static NSInteger const kRCNFetchResponseHTTPStatusTooManyRequests = 429; |
| 52 | +static NSInteger const kRCNFetchResponseHTTPStatusCodeBadGateway = 502; |
| 53 | +static NSInteger const kRCNFetchResponseHTTPStatusCodeServiceUnavailable = 503; |
| 54 | +static NSInteger const kRCNFetchResponseHTTPStatusCodeGatewayTimeout = 504; |
| 55 | + |
| 56 | +/// Invalidation message field names. |
47 | 57 | static NSString *const kTemplateVersionNumberKey = @"latestTemplateVersionNumber";
|
48 | 58 | static NSString *const kIsFeatureDisabled = @"featureDisabled";
|
49 | 59 |
|
|
52 | 62 | /// @param error Error message on failure.
|
53 | 63 | typedef void (^RCNConfigUpdateCompletion)(NSError *_Nullable error);
|
54 | 64 |
|
55 |
| -static NSTimeInterval gTimeoutSeconds = 4320; |
| 65 | +static NSTimeInterval gTimeoutSeconds = 330; |
56 | 66 | static NSInteger const gFetchAttempts = 3;
|
57 | 67 |
|
58 | 68 | // Retry parameters
|
@@ -552,18 +562,42 @@ - (void)URLSession:(NSURLSession *)session
|
552 | 562 | }
|
553 | 563 | }
|
554 | 564 |
|
| 565 | +/// Check if response code is retryable |
| 566 | +- (bool)isStatusCodeRetryable:(NSInteger)statusCode { |
| 567 | + return statusCode == kRCNFetchResponseHTTPStatusClientTimeout || |
| 568 | + statusCode == kRCNFetchResponseHTTPStatusTooManyRequests || |
| 569 | + statusCode == kRCNFetchResponseHTTPStatusCodeServiceUnavailable || |
| 570 | + statusCode == kRCNFetchResponseHTTPStatusCodeBadGateway || |
| 571 | + statusCode == kRCNFetchResponseHTTPStatusCodeGatewayTimeout; |
| 572 | +} |
| 573 | + |
555 | 574 | /// Delegate to handle initial reply from the server
|
556 | 575 | - (void)URLSession:(NSURLSession *)session
|
557 | 576 | dataTask:(NSURLSessionDataTask *)dataTask
|
558 | 577 | didReceiveResponse:(NSURLResponse *)response
|
559 | 578 | completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
|
560 | 579 | _isRequestInProgress = false;
|
561 | 580 | NSHTTPURLResponse *_httpURLResponse = (NSHTTPURLResponse *)response;
|
562 |
| - if ([_httpURLResponse statusCode] != 200) { |
| 581 | + NSInteger statusCode = [_httpURLResponse statusCode]; |
| 582 | + if (statusCode != kRCNFetchResponseHTTPStatusOk) { |
563 | 583 | [self pauseRealtimeStream];
|
564 |
| - [self retryHTTPConnection]; |
| 584 | + if ([self isStatusCodeRetryable:statusCode]) { |
| 585 | + [self retryHTTPConnection]; |
| 586 | + } else { |
| 587 | + NSError *error = [NSError |
| 588 | + errorWithDomain:FIRRemoteConfigRealtimeErrorDomain |
| 589 | + code:FIRRemoteConfigRealtimeErrorStream |
| 590 | + userInfo:@{ |
| 591 | + NSLocalizedDescriptionKey : [NSString |
| 592 | + stringWithFormat:@"StreamError: Received non-retryable status code: %@", |
| 593 | + [@(statusCode) stringValue]] |
| 594 | + }]; |
| 595 | + FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000021", @"Cannot establish connection. Error: %@", |
| 596 | + error); |
| 597 | + [self propogateErrors:error]; |
| 598 | + } |
565 | 599 | } else {
|
566 |
| - // on success reset retry parameters |
| 600 | + /// on success reset retry parameters |
567 | 601 | _remainingRetryCount = gMaxRetries;
|
568 | 602 | _retrySeconds = arc4random_uniform(5) + 1;
|
569 | 603 |
|
|
0 commit comments