Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Close #8846: Re-subscribe FxA push subscription on subscriptionExpired #8883

Merged
merged 2 commits into from
Nov 17, 2020

Conversation

jonalmeida
Copy link
Contributor

This is a workaround fix to re-enable Send Tab when we are notified
about the subscriptionExpired flag. Until #7143 is fixed, we need to
avoid calling registrationRenewal to avoid going into an unfixable
state.

In the context of the FxaPushSupportFeature, we know that our end goal
is to call push.subscribe(fxaPushScope), so we can by pass the
verifyConnection call assuming that our native push client is
always has the latest push token and knows how to invalidate the
endpoint with the Autopush server.

Closes #8846

Pull Request checklist

  • Quality: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended)
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry or does not need one
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features

After merge

  • Milestone: Make sure issues closed by this pull request are added to the milestone of the version currently in development.
  • Breaking Changes: If this is a breaking change, please push a draft PR on Reference Browser to address the breaking issues.

@jonalmeida jonalmeida added the 🕵️‍♀️ needs review PRs that need to be reviewed label Nov 3, 2020
@jonalmeida jonalmeida requested a review from grigoryk as a code owner November 3, 2020 18:12
@mergify
Copy link
Contributor

mergify bot commented Nov 3, 2020

This pull request has conflicts when rebasing. Could you fix it @jonalmeida? 🙏

@jonalmeida
Copy link
Contributor Author

This pull request has conflicts when rebasing. Could you fix it @jonalmeida? 🙏

external-content duckduckgo com

@mergify
Copy link
Contributor

mergify bot commented Nov 16, 2020

This pull request has conflicts when rebasing. Could you fix it @jonalmeida? 🙏

Copy link
Contributor

@grigoryk grigoryk left a comment

Choose a reason for hiding this comment

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

This is inline with what we've discussed. I've left some suggestions about additional breadcrumbs, and also a note about a possible infinite DDOS loop.

logger.info("Subscribing to FxA push failed at login.", e)
},
onSubscribe = { subscription ->
logger.info("Created a new subscription: $subscription")
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be a useful breadcrumb to have as well

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 don't think we would ever get this breadcrumb though. This is part of the success path so we would not get an exception in the crash reporter.

If we do one day get into the failure path, this breadcrumb would still not be helpful because our subscription.endpoint == oldEndpoint check would give us the old and new state already.

}

CoroutineScope(Dispatchers.Main).launch {
account.deviceConstellation().setDevicePushSubscription(subscription.into())
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe leave a unique breadcrumb here as well?

This could fail; if it fails, our re-subscription didn't fully work - we have a new endpoint, but it's not recorded on the device record.

If this succeeds, I'm assuming this method will clear the "needs resubscription" flag?

If this fails, what happens? How do we recover?

Next time we fetch our device record, see the bad flag, and attempt again? This sounds like a potential loop to me, without a circuit breaker in case something goes wrong (e.g. maybe there's a sever bug where they don't clear the "needs resub.." flag, and we end up ddossing both autopush and fxa).

It'll be nice to treat resubscription as an atomic operation spanning several services, all of which must succeed in order for us to successfully complete resubscription. We can also take one more step back, and declare resubscription configured to be successful once we receive an fxa push message!

That's definition out of scope here, but I'd suggest thinking about how you'd prevent this bad loop from happening, at least.

This is also a pattern we have in at least one other place (fxa auth loop), which did actually bite us due to a server-side bug (we'd think we've successfully recovered from an auth problem, only to be told by sync that it hit a 401, we'd then recover from an auth problem, only to be told by sync that it hit a 401, etc etc etc...). In that case, we've added circuit breaker logic.

If you think a loop is indeed possible here, can you file a follow-up to consider our options here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this succeeds, I'm assuming this method will clear the "needs resubscription" flag?

Yes, it should do that on the server end when the request goes through.

Next time we fetch our device record, see the bad flag, and attempt again? This sounds like a potential loop to me, without a circuit breaker in case something goes wrong (e.g. maybe there's a sever bug where they don't clear the "needs resub.." flag, and we end up ddossing both autopush and fxa).

It'll be nice to treat resubscription as an atomic operation spanning several services, all of which must succeed in order for us to successfully complete resubscription. We can also take one more step back, and declare resubscription configured to be successful once we receive an fxa push message!

That's definition out of scope here, but I'd suggest thinking about how you'd prevent this bad loop from happening, at least.

This is also a pattern we have in at least one other place (fxa auth loop), which did actually bite us due to a server-side bug (we'd think we've successfully recovered from an auth problem, only to be told by sync that it hit a 401, we'd then recover from an auth problem, only to be told by sync that it hit a 401, etc etc etc...). In that case, we've added circuit breaker logic.

If you think a loop is indeed possible here, can you file a follow-up to consider our options here?

To prevent us from going through this loop and DDOS-ing our own servers, we have the VerificationDelegate to rate-limit ourselves. App services have also re-implemented this internally so we can remove our rate-limiting code in the future as well when it covers this endpoint too.

docs/changelog.md Outdated Show resolved Hide resolved
…criptionExpired

This is a workaround fix to re-enable Send Tab when we are notified
about the subscriptionExpired flag. Until mozilla-mobile#7143 is fixed, we need to
avoid calling `registrationRenewal` to avoid going into an unfixable
state.

In the context of the FxaPushSupportFeature, we know that our end goal
is to call `push.subscribe(fxaPushScope)`, so we can by pass the
`verifyConnection` call **assuming** that our native push client is
always has the latest push token and knows how to invalidate the
endpoint with the Autopush server.
@jonalmeida jonalmeida added 🛬 needs landing PRs that are ready to land and removed 🕵️‍♀️ needs review PRs that need to be reviewed labels Nov 17, 2020
@mergify mergify bot merged commit d5524f7 into mozilla-mobile:master Nov 17, 2020
@jonalmeida jonalmeida deleted the issue-8846 branch November 17, 2020 16:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🛬 needs landing PRs that are ready to land
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-subscribe only FxA push subscription when subscriptionExpired true
2 participants