braze-inc / braze-swift-sdk

Braze SDK for the Apple ecosystem, including: iOS, macOS, iPadOS, visionOS, tvOS
https://www.braze.com
Other
52 stars 19 forks source link

[Bug]: Updated feature flag values don't always get updated on initialization #110

Closed markanderson-underdog closed 4 months ago

markanderson-underdog commented 9 months ago

Platform

iOS

Platform Version

iOS 17.2

Braze SDK Version

7.5.0

Xcode Version

15.2

Computer Processor

Apple (M1)

Repro Rate

80% of the time

Steps To Reproduce

  1. Configure a remote feature flag in Braze
  2. Set the rollout of the Feature Flag to e.g. 100% / ON
  3. Launch app, which inits Braze and receives value of the flag
  4. Set rollout of the feature flag to 0% / OFF
  5. Kill + relaunch the app, re-initing Braze to receive value of the flag

Expected Behavior

After step 5, new Feature Flag value (off) is respected and given to the application on init-ing Braze

Actual Incorrect Behavior

I can see in a Network Proxy tool that the Braze SDK is indeed fetching the new FF and it is received as off from the API, often (~80%) the Braze SDK inits before the API response comes in to update the FF value, and as a result the incorrect value of ON is given to the app on init.

See attached images, taken around step 5 of the STR: First image - Braze is initialized, and we check the feature flags (shows the flag is ON, even though the flag is set to OFF on the backend) Screenshot 2024-02-21 at 2 10 46 PM Second image - about ~350 ms later, the braze request to sync the flags returns, and shows no flags (which is correct) Screenshot 2024-02-21 at 2 10 37 PM Third image - almost 1 second later, if we re-query the flags, we're finally shown correct state Screenshot 2024-02-21 at 2 10 52 PM

Verbose Logs

No response

Additional Information

No response

jerielng commented 8 months ago

Hi @markanderson-underdog, thanks for raising this. If I understand correctly, you are receiving the 100%-on value at your first launch of the app, and then while the app is still opened, turning it to 0% remotely before quitting and re-opening? Are you re-syncing your feature flags before killing the app?

I believe that should be expected behavior, unless I've misrepresented the above scenario? Feature flag values are only refreshed whenever that /feature_flags/sync API call is made. If no refresh call is made between steps 4 and 5, the Braze SDK will be re-initialized upon launch with whatever cached values there were from the previous sync. When the SDK is initialized, it kicks off a refresh call as soon as it can, but until that refresh call returns, it has no knowledge of the server's last state.

lowip commented 4 months ago

Hi @markanderson-underdog,

I'm closing this ticket due to inactivity, feel free to re-open it if you're still facing this issue.

Best,