DataDog / dd-sdk-ios

Datadog SDK for iOS - Swift and Objective-C.
Apache License 2.0
219 stars 127 forks source link

RUM-3175 fix: Fix race condition during consent change (pending → granted) #2063

Closed ganeshnj closed 1 week ago

ganeshnj commented 1 month ago

What and why?

📦🐞 This PR fixes a race condition that occurs during the change of tracking consent from .pending to .granted. This issue could result in the loss of events recorded on the current thread right before the consent change.

How?

The fix involves synchronizing data migration on the context queue to prevent conflicts with ongoing "event write" operations. This change guarantees that all latest events are accurately migrated based on the updated consent state.

Review checklist

datadog-datadog-prod-us1[bot] commented 1 month ago

Datadog Report

Branch report: ganeshnj/fix/consent-migration Commit report: 817a0e1 Test service: dd-sdk-ios

:white_check_mark: 0 Failed, 3473 Passed, 0 Skipped, 3m 35.42s Total Time :small_red_triangle_down: Test Sessions change in coverage: 2 decreased, 5 increased, 7 no change

:small_red_triangle_down: Code Coverage Decreases vs Default Branch (2)

ncreated commented 1 week ago

(...) to call the migration from the context queue, also after publishing the new consent.

@maxep Fair call ✅. I continued this work fixing it in proposed way ☝️. It's not necessary to publish the consent before migration task as migration depends on the new consent value explicitly.

ncreated commented 1 week ago

/merge

dd-devflow[bot] commented 1 week ago

:steam_locomotive: MergeQueue: pull request added to the queue

The median merge time in develop is 29m.

Use /merge -c to cancel this operation!

dd-devflow[bot] commented 1 week ago

:rotating_light: MergeQueue: This merge request is in error

mergequeue build completed successfully, but the github api returned an error while merging the pr. It's probably because:

Details Error: PUT https://api.github.com/repos/DataDog/dd-sdk-ios/pulls/2063/merge: 405 Required status check "dd-gitlab/Sync GH Checks" is expected. [] FullStacktrace: activity error (type: github.GithubService_MergePullRequest, scheduledEventID: 41, startedEventID: 42, identity: 1@github-worker-78dd5544fc-6gzkw@): PUT https://api.github.com/repos/DataDog/dd-sdk-ios/pulls/2063/merge: 405 Required status check "dd-gitlab/Sync GH Checks" is expected. [] (type: GitFailure, retryable: false): PUT https://api.github.com/repos/DataDog/dd-sdk-ios/pulls/2063/merge: 405 Required status check "dd-gitlab/Sync GH Checks" is expected. [] (type: ErrorResponse, retryable: true)

If you need support, contact us on Slack #devflow with those details!

ncreated commented 1 week ago

/merge

dd-devflow[bot] commented 1 week ago

:steam_locomotive: MergeQueue: waiting for PR to be ready

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals. Note: if you pushed new commits since the last approval, you may need additional approval. You can remove it from the waiting list with /remove command.

Use /merge -c to cancel this operation!

dd-devflow[bot] commented 1 week ago

:steam_locomotive: MergeQueue: pull request added to the queue

The median merge time in develop is 29m.

Use /merge -c to cancel this operation!