From 6093118ba13c50d506d1be573c71ccbaafc63e5f Mon Sep 17 00:00:00 2001 From: Russell Hancox Date: Wed, 31 Jul 2024 13:29:25 -0400 Subject: [PATCH] sync: Improve logging when connection restored, avoid retries. (#1408) * sync: Improve logging when connection restored, avoid retries. Don't retry requests if the error is that the machine is offline --- Source/santasyncservice/SNTSyncManager.m | 5 +++-- Source/santasyncservice/SNTSyncStage.mm | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/santasyncservice/SNTSyncManager.m b/Source/santasyncservice/SNTSyncManager.m index 84468819d..193e1c77e 100644 --- a/Source/santasyncservice/SNTSyncManager.m +++ b/Source/santasyncservice/SNTSyncManager.m @@ -257,8 +257,8 @@ - (SNTSyncStatusType)preflightOnly:(BOOL)preflightOnly { return [self eventUploadWithSyncState:syncState]; } - LOGE(@"Preflight failed, will try again once %@ is reachable", - [[SNTConfigurator configurator] syncBaseURL].absoluteString); + SLOGE(@"Preflight failed, will try again once %@ is reachable", + [[SNTConfigurator configurator] syncBaseURL].absoluteString); [self startReachability]; return SNTSyncStatusTypePreflightFailed; } @@ -386,6 +386,7 @@ - (SNTSyncState *)createSyncStateWithStatus:(SNTSyncStatusType *)status { - (void)setReachable:(BOOL)reachable { _reachable = reachable; if (reachable) { + LOGD(@"Internet connection has been restored, triggering a new sync."); [self stopReachability]; [self sync]; } diff --git a/Source/santasyncservice/SNTSyncStage.mm b/Source/santasyncservice/SNTSyncStage.mm index 71e9cac05..4f2829693 100644 --- a/Source/santasyncservice/SNTSyncStage.mm +++ b/Source/santasyncservice/SNTSyncStage.mm @@ -14,6 +14,7 @@ #import "Source/santasyncservice/SNTSyncStage.h" +#include #import #import "Source/common/SNTCommonEnums.h" @@ -176,6 +177,11 @@ - (NSData *)dataFromRequest:(NSURLRequest *)request data = [self performRequest:request timeout:timeout response:&response error:&requestError]; if (response.statusCode == 200) break; + // If the original request failed because of a "No network" error, break out of the loop, + // subsequent retries are pointless and the entire sync will be retried once a connection + // is established. + if (requestError.code == NSURLErrorNotConnectedToInternet) break; + // If the original request failed because of an auth error, attempt to get a new XSRF token and // try again. Unfortunately some servers cause NSURLSession to return 'client cert required' or // 'could not parse response' when a 403 occurs and SSL cert auth is enabled.