BranchMetrics / android-branch-deep-linking-attribution

The Branch Android SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
https://docs.branch.io/pages/apps/android/
MIT License
395 stars 155 forks source link

Race condition on fetching and using GAID #1207

Open lamphamTL opened 1 week ago

lamphamTL commented 1 week ago

Describe the bug

It happens to us that a lot of install requests don't include the field aaid, but purchase and new customer do. This issue doesn't happen for all the cases. After investigating, we found that this is potentially a concurrency problem. On our side, we invoke

Branch.getInstance().disableTracking(..)

This call goes the way down to Branch#registerAppInit(). Within this method:

initTasks(request, ignoreWaitLocks);

requestQueue_.processNextQueueItem("registerAppInit");

These 2 calls cause the issue:

There is a set of locks being introduced that can made the 2nd request requestQueue_.processNextQueueItem wait for the first one to be finished. However, within initTask, ignoreWaitLocks is passed as true (this value comes from TrackingController#onTrackingEnabled), as a consequence, lock is not added into the set, so the 2nd request is not aware of the other ones being executed and goes ahead, which leads to the fact that gaid is potentially not ready when updateGAdsParams get invoked.

Is this correct or do I miss anything?

Steps to reproduce

  1. Call Branch.getInstance().disableTracking(..);

Expected behavior

gaid is used only after gaid fetching is finished.

SDK Version

5.11

Make and Model

Emulator Pixel 8 API 34

OS

14

Additional Information/Context

No response