-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Make backoff account for already-elapsed time. #1712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically LGTM
timerID:self.timerID | ||
block:^{ | ||
FSTStrongify(self); | ||
self.lastAttemptTime = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If self
has become nil
the the assignment will nil-dispatch so strictly speaking that's okay, but should we really call the block?
I think this should be:
^{
FSTStrongify(self);
if (self) {
self.lastAttemptTime = [[NSDate date] timeIntervalSince1970];
block();
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable. Fixed.
@mikelehen Sorry, only recently noticed this.
Can you give an example of when backoff would exhibit incorrect behavior without this change? From a cursory glance, this change seems to protect against clock readjustment. In C++, there are two implementations of the |
@var-const The goal is to avoid waiting the entire backoff delay if some of it has already elapsed (because we didn't have a reason to reconnect right away). In particular, imagine:
(similarly if the backoff delay is at 10 seconds, and you wait 6 seconds before initiating a get() that triggers a stream retry, we should only back off for the remaining 4 seconds, rather than wait a full 10 seconds.) |
@var-const Are you looking at porting this? Else, I can. I intentionally skipped the C++ version because I knew it was unused and I suck at C++ and was trying to get this PR in before I went OOO. But I can take a stab at it now unless you're already messing with the C++ backoff implementation. |
@mikelehen Ah, thanks for the explanation. I'm not blocked by this, so I'm fine if you port it (and happy to help with C++; current time would be either |
Thanks for the pointers! steady_clock is handy. I sent you a PR: #1787 |
[Port of https://github.com/firebase/firebase-js-sdk/pull/1132]
Note: We actually have a not-yet-used c++ implementation of exponential backoff too. I tried to update it, but it was hard. So I'm punting on that for the moment and will do that in a separate PR later.