From 838ee8021845becf42dbacd7a45dbbce798b6010 Mon Sep 17 00:00:00 2001 From: Michael Lehenbauer Date: Thu, 26 Oct 2017 13:57:26 -0700 Subject: b/67423356: Exponential backoff on writes should back off until the first successful write (#408) Port the logic from Android / web to delay backoff reset until the first successful write on the stream. --- Firestore/Source/Remote/FSTDatastore.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Firestore/Source/Remote/FSTDatastore.m b/Firestore/Source/Remote/FSTDatastore.m index b788df9..95ee12c 100644 --- a/Firestore/Source/Remote/FSTDatastore.m +++ b/Firestore/Source/Remote/FSTDatastore.m @@ -917,9 +917,6 @@ typedef NS_ENUM(NSInteger, FSTStreamState) { FSTLog(@"FSTWriteStream %p response: %@", (__bridge void *)self, response); [self.workerDispatchQueue verifyIsCurrentQueue]; - // A successful response means the stream is healthy. - [self.backoff reset]; - // Always capture the last stream token. self.lastStreamToken = response.streamToken; @@ -929,6 +926,11 @@ typedef NS_ENUM(NSInteger, FSTStreamState) { [self.delegate writeStreamDidCompleteHandshake]; } else { + // A successful first write response means the stream is healthy. + // Note that we could consider a successful handshake healthy, however, the write itself + // might be causing an error we want to back off from. + [self.backoff reset]; + FSTSnapshotVersion *commitVersion = [_serializer decodedVersion:response.commitTime]; NSMutableArray *protos = response.writeResultsArray; NSMutableArray *results = [NSMutableArray arrayWithCapacity:protos.count]; -- cgit v1.2.3