Skip to content

Commit

Permalink
sync: Improve logging when connection restored, avoid retries. (#1408)
Browse files Browse the repository at this point in the history
* sync: Improve logging when connection restored, avoid retries.

Don't retry requests if the error is that the machine is offline
  • Loading branch information
russellhancox authored Jul 31, 2024
1 parent 6719d4c commit 6093118
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Source/santasyncservice/SNTSyncManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
}
Expand Down
6 changes: 6 additions & 0 deletions Source/santasyncservice/SNTSyncStage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#import "Source/santasyncservice/SNTSyncStage.h"

#include <Foundation/Foundation.h>
#import <MOLXPCConnection/MOLXPCConnection.h>

#import "Source/common/SNTCommonEnums.h"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6093118

Please sign in to comment.