Skip to content
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

Update network retry behavior to extend retries, add jitter #148

Merged
merged 3 commits into from
Mar 26, 2024

Conversation

evan-masseau
Copy link
Contributor

@evan-masseau evan-masseau commented Mar 22, 2024

Description

This should match the Swift SDK retry behavior as I understood it. I tried to make the test very readable, would appreciate @ndurell or @ajaysubra confirming my logic.

First of two PRs regarding network rate limits.

Check List

  • Are you changing anything with the public API?
    • No
  • Are your changes backwards compatible with previous SDK Versions?
    • Yes
  • Have you tested this change on real device?
    • Emulator is sufficient
  • Have you added unit test coverage for your changes?
    • Yes
  • Have you verified that your changes are compatible with all Android versions the SDK currently supports?
    • N/A

Changelog / Code Overview

  • Retry 50 times before failure
  • Updated my exponential backoff calculation
  • Added jitter
  • Re-worked the unit test based on better understanding of the thread Handler behavior

Test Plan

  • Unit test and debugged on a device after forcing artificial 429 responses

Related Issues/Tickets

CHNL-6779

- Retry 50 times before failure
- Use same timing logic for the "exponential" backoff with jitter
- Re-worked the unit test based on better understanding of the thread Handler behavior
@evan-masseau evan-masseau added enhancement New feature or request minor-release For issues/code that belong in a minor release per semantic versioning guidelines labels Mar 23, 2024
handler?.postDelayed(this, flushInterval)
}

private fun computeRetryInterval(attempts: Int): Long {
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic here looks totally sound. Just wondering if this is a mirror of what we do on iOS? Like are the limits we apply to our jitter the same, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Default min/max retry intervals 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.

Yes I believe so. Would like a confirmation of my reading from Noah or Ajay. The difference is mostly just that I compute the retry time all in one function, whereas on iOS its split up into a couple different parts of the network queueing code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ndurell @ajaysubra when one of you has a chance ^

Copy link
Contributor

Choose a reason for hiding this comment

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

I took a gander at the iOS code and this looks inline. Looks like based on this message that Evan posted, we have at least 7 attempts before hitting the 3 min threshold if the app is active. This lines up with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the verification!

private fun computeRetryInterval(attempts: Int): Long {
val minRetryInterval = flushInterval
val jitterSeconds = Registry.config.networkJitterRange.random()
val exponentialBackoff = (2.0.pow(attempts).toLong() + jitterSeconds).times(1_000)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing the 1000 converts seconds to milliseconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep!

handler?.postDelayed(this, flushInterval)
}

private fun computeRetryInterval(attempts: Int): Long {
Copy link
Contributor

Choose a reason for hiding this comment

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

I took a gander at the iOS code and this looks inline. Looks like based on this message that Evan posted, we have at least 7 attempts before hitting the 3 min threshold if the app is active. This lines up with that.

@evan-masseau evan-masseau merged commit f5107fa into master Mar 26, 2024
2 checks passed
@evan-masseau evan-masseau deleted the ecm/CHNL-6779 branch March 26, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request minor-release For issues/code that belong in a minor release per semantic versioning guidelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants