Skip to content

Fix handler for multiple calls of -[FIRInstanceID instanceIDWithHandler:] (#2445) #2559

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

Merged
merged 12 commits into from
Mar 24, 2019

Conversation

maksymmalyhin
Copy link
Contributor

This is a fix for #2445:

  • -[FIRInstanceID instanceIDWithHandler:] accumulate handlers while there is ongoing request to perform all of them on completion

@charlotteliang charlotteliang self-requested a review March 15, 2019 05:14
if (aHandler) {
[self.defaultTokenFetchHandler addHandler:aHandler];
}

if (self.isFetchingDefaultToken || self.isDefaultTokenFetchScheduled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to check this flag or just check if defaultTokenFetchHandler.count > 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my first try was to replace isFetchingDefaultToken by checking defaultTokenFetchHandler.count, but then it is hard to handle retry logic due to the way it is implemented. Also, in this case the handler cannot be optional (which is the case e.g. in #2562). Keeping both, the flag and defaultTokenFetchHandler allows to make less changes to the existing logic.

if (aHandler) {
[self.defaultTokenFetchHandler addHandler:aHandler];
}

if (self.isFetchingDefaultToken || self.isDefaultTokenFetchScheduled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like you can also get rid of isDefaultTokenFetchScheduled. Because you have the first original call back in and retry just calling with nil.

But if you don't feel comfortable, you can leave it like this for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, currently isDefaultTokenFetchScheduled prevents additional requests to be sent while [self retryIntervalToFetchDefaultToken] timeout, so, I think, we still need it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since we are adding a new logic to the existing code that could replace the old boolean value. We should do that. We are trying to simplify the iid logic especially your new queue should be able to handle it.

So one way we can do is to have a defaultTokenWithRetry:(BOOL) handler:
So that if it's retry, we always go through, without adding a new handler to the queue. Otherwise, adding it to the queue and check if it's >1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed an update. Would you take a look if it is what you meant?

@maksymmalyhin maksymmalyhin self-assigned this Mar 15, 2019
@maksymmalyhin
Copy link
Contributor Author

maksymmalyhin commented Mar 15, 2019

@chliangGoogle Thank you for the attentive review! The logic looks to me a bit difficult to follow with the current implementation. E.g. defaultTokenWithHandler: method currently is responsible for 3 separate things:

  1. Fetching the token itself
  2. Retry
  3. Merge token requests

As I mentioned, I would like to discuss possible ways to improve the code.

Copy link
Contributor

@charlotteliang charlotteliang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. With a few nit picking.

@@ -860,7 +861,7 @@ - (NSInteger)retryIntervalToFetchDefaultToken {
}

- (void)fetchDefaultToken {
if (self.isFetchingDefaultToken) {
if (self.defaultTokenFetchHandler != nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might have to merge, this function would not be needed.

- (void)defaultTokenWithHandler:(FIRInstanceIDTokenHandler)handler {
if (self.isFetchingDefaultToken || self.isDefaultTokenFetchScheduled) {
- (void)defaultTokenWithHandler:(nullable FIRInstanceIDTokenHandler)aHandler {
[self defaultTokenWithRetry:NO handler:aHandler];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can get rid of defaultTokenWithHandler: and use the new one instead every where.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not to use defaultTokenWithRetry:handler: everywhere because the retry argument is kind of an implementation detail of defaultTokenWithHandler: method.

@chliangGoogle Let me know if you still would prefer to get rid of it, I'll create a separate PR for it then.

Conflicts:
	Firebase/InstanceID/FIRInstanceID.m
@maksymmalyhin maksymmalyhin merged commit 0738c0e into master Mar 24, 2019
@maksymmalyhin maksymmalyhin deleted the mm/instanceID-handler-2445 branch June 13, 2019 14:58
@firebase firebase locked and limited conversation to collaborators Oct 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants