Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 6093118

Browse files
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
1 parent 6719d4c commit 6093118

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

‎Source/santasyncservice/SNTSyncManager.m‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ - (SNTSyncStatusType)preflightOnly:(BOOL)preflightOnly {
257257
return [self eventUploadWithSyncState:syncState];
258258
}
259259

260-
LOGE(@"Preflight failed, will try again once %@ is reachable",
261-
[[SNTConfigurator configurator] syncBaseURL].absoluteString);
260+
SLOGE(@"Preflight failed, will try again once %@ is reachable",
261+
[[SNTConfigurator configurator] syncBaseURL].absoluteString);
262262
[self startReachability];
263263
return SNTSyncStatusTypePreflightFailed;
264264
}
@@ -386,6 +386,7 @@ - (SNTSyncState *)createSyncStateWithStatus:(SNTSyncStatusType *)status {
386386
- (void)setReachable:(BOOL)reachable {
387387
_reachable = reachable;
388388
if (reachable) {
389+
LOGD(@"Internet connection has been restored, triggering a new sync.");
389390
[self stopReachability];
390391
[self sync];
391392
}

‎Source/santasyncservice/SNTSyncStage.mm‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#import "Source/santasyncservice/SNTSyncStage.h"
1616

17+
#include <Foundation/Foundation.h>
1718
#import <MOLXPCConnection/MOLXPCConnection.h>
1819

1920
#import "Source/common/SNTCommonEnums.h"
@@ -176,6 +177,11 @@ - (NSData *)dataFromRequest:(NSURLRequest *)request
176177
data = [self performRequest:request timeout:timeout response:&response error:&requestError];
177178
if (response.statusCode == 200) break;
178179

180+
// If the original request failed because of a "No network" error, break out of the loop,
181+
// subsequent retries are pointless and the entire sync will be retried once a connection
182+
// is established.
183+
if (requestError.code == NSURLErrorNotConnectedToInternet) break;
184+
179185
// If the original request failed because of an auth error, attempt to get a new XSRF token and
180186
// try again. Unfortunately some servers cause NSURLSession to return 'client cert required' or
181187
// 'could not parse response' when a 403 occurs and SSL cert auth is enabled.

0 commit comments

Comments
 (0)