launchdarkly / ios-client-sdk

LaunchDarkly Client-side SDK for iOS (Swift and Obj-C)
https://docs.launchdarkly.com/sdk/client-side/ios
Other
68 stars 84 forks source link

Fixing crashes when using overflowing values #246

Closed delannoyk closed 3 years ago

delannoyk commented 3 years ago

Requirements

Related issues

I didn't create a GitHub issue for this, but happy to if necessary.

Describe the solution you've provided

Int(exactly:) will return nil in case of an overflow whereas Int(_:) will just crash. When converting the Double to an Int, if it fails, we now use Int.max as a rescue.

Describe alternatives you've considered

Fixing the crash was I think necessary. That being said, we only noticed that crash because we wanted to disable updates to our feature flags during a user session (we want to have a consistent experience throughout the session). There's no way that I could find to do that right now, so we opted for having a really long update interval. Adding this feature would have been nice too, but was more work that I intended.

Additional context

Nothing else from me.

torchhound commented 3 years ago

Hi @delannoyk thanks for submitting this PR! We will review this internally to check if this fits with intended SDK behavior.

bwoskow-ld commented 3 years ago

Hi @delannoyk,

While our SDK team hasn't yet had a chance to look at this issue, I did want to recommend that you use smaller intervals if you haven't already done so. Our SDK isn't really designed to operate with "really long" intervals because, depending on which intervals you extends, flag values will be stale (which is actually your intent here) and the event buffer is more likely to overflow and start dropping events.

If you choose to proceed with large intervals, consider setting them to the max int value so as to avoid running into this crash.

Cheers, @bwoskow-ld

gwhelanLD commented 3 years ago

Thanks again for the contribution! It's been included in the 5.4.2 release.

Thanks, @gwhelanLD

delannoyk commented 3 years ago

Thank you for the update 👍🏻