aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore
diff options
context:
space:
mode:
authorGravatar Michael Lehenbauer <mikelehen@gmail.com>2018-06-26 12:11:40 -0700
committerGravatar GitHub <noreply@github.com>2018-06-26 12:11:40 -0700
commitae326815e4008639edd95bbd7d1ab4cc8e9425b8 (patch)
tree3016f1546504498a059f0281e97e78006bd3722d /Firestore
parent2810a09c582b09104c04f16e5a3086cbe3e79d23 (diff)
Improves "Could not reach Firestore backend." log message. (#1455)
Diffstat (limited to 'Firestore')
-rw-r--r--Firestore/Source/Remote/FSTOnlineStateTracker.h2
-rw-r--r--Firestore/Source/Remote/FSTOnlineStateTracker.mm27
-rw-r--r--Firestore/Source/Remote/FSTRemoteStore.mm6
3 files changed, 24 insertions, 11 deletions
diff --git a/Firestore/Source/Remote/FSTOnlineStateTracker.h b/Firestore/Source/Remote/FSTOnlineStateTracker.h
index 2521c84..340b641 100644
--- a/Firestore/Source/Remote/FSTOnlineStateTracker.h
+++ b/Firestore/Source/Remote/FSTOnlineStateTracker.h
@@ -57,7 +57,7 @@ NS_ASSUME_NONNULL_BEGIN
* We then may allow multiple failures (based on kMaxWatchStreamFailures) before we actually
* transition to FSTOnlineStateOffline.
*/
-- (void)handleWatchStreamFailure;
+- (void)handleWatchStreamFailure:(NSError *)error;
/**
* Explicitly sets the FSTOnlineState to the specified state.
diff --git a/Firestore/Source/Remote/FSTOnlineStateTracker.mm b/Firestore/Source/Remote/FSTOnlineStateTracker.mm
index fb993e5..a5c2b38 100644
--- a/Firestore/Source/Remote/FSTOnlineStateTracker.mm
+++ b/Firestore/Source/Remote/FSTOnlineStateTracker.mm
@@ -84,11 +84,10 @@ static const NSTimeInterval kOnlineStateTimeout = 10;
HARD_ASSERT(
self.state == FSTOnlineStateUnknown,
"Timer should be canceled if we transitioned to a different state.");
- LOG_DEBUG(
- "Watch stream didn't reach Online or Offline within %s seconds. "
- "Considering client offline.",
- kOnlineStateTimeout);
- [self logClientOfflineWarningIfNecessary];
+ [self logClientOfflineWarningIfNecessaryWithReason:
+ [NSString
+ stringWithFormat:@"Backend didn't respond within %f seconds.",
+ kOnlineStateTimeout]];
[self setAndBroadcastState:FSTOnlineStateOffline];
// NOTE: handleWatchStreamFailure will continue to increment
@@ -98,7 +97,7 @@ static const NSTimeInterval kOnlineStateTimeout = 10;
}
}
-- (void)handleWatchStreamFailure {
+- (void)handleWatchStreamFailure:(NSError *)error {
if (self.state == FSTOnlineStateOnline) {
[self setAndBroadcastState:FSTOnlineStateUnknown];
@@ -110,7 +109,9 @@ static const NSTimeInterval kOnlineStateTimeout = 10;
self.watchStreamFailures++;
if (self.watchStreamFailures >= kMaxWatchStreamFailures) {
[self clearOnlineStateTimer];
- [self logClientOfflineWarningIfNecessary];
+ [self logClientOfflineWarningIfNecessaryWithReason:
+ [NSString stringWithFormat:@"Connection failed %d times. Most recent error: %@",
+ kMaxWatchStreamFailures, error]];
[self setAndBroadcastState:FSTOnlineStateOffline];
}
}
@@ -136,10 +137,18 @@ static const NSTimeInterval kOnlineStateTimeout = 10;
}
}
-- (void)logClientOfflineWarningIfNecessary {
+- (void)logClientOfflineWarningIfNecessaryWithReason:(NSString *)reason {
+ NSString *message = [NSString
+ stringWithFormat:
+ @"Could not reach Cloud Firestore backend. %@\n This typically indicates that your "
+ @"device does not have a healthy Internet connection at the moment. The client will "
+ @"operate in offline mode until it is able to successfully connect to the backend.",
+ reason];
if (self.shouldWarnClientIsOffline) {
- LOG_WARN("Could not reach Firestore backend.");
+ LOG_WARN("%s", message);
self.shouldWarnClientIsOffline = NO;
+ } else {
+ LOG_DEBUG("%s", message);
}
}
diff --git a/Firestore/Source/Remote/FSTRemoteStore.mm b/Firestore/Source/Remote/FSTRemoteStore.mm
index 4309c74..4d8aa7e 100644
--- a/Firestore/Source/Remote/FSTRemoteStore.mm
+++ b/Firestore/Source/Remote/FSTRemoteStore.mm
@@ -323,11 +323,15 @@ static const int kMaxPendingWrites = 10;
"enabled");
[self cleanUpWatchStreamState];
- [self.onlineStateTracker handleWatchStreamFailure];
// If the watch stream closed due to an error, retry the connection if there are any active
// watch targets.
if ([self shouldStartWatchStream]) {
+ if (error) {
+ // There should generally be an error if the watch stream was closed when it's still needed,
+ // but it's not quite worth asserting.
+ [self.onlineStateTracker handleWatchStreamFailure:error];
+ }
[self startWatchStream];
} else {
// We don't need to restart the watch stream because there are no active targets. The online