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

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

Merged
merged 3 commits into from
Nov 6, 2024

Conversation

ganeshnj
Copy link
Contributor

@ganeshnj ganeshnj commented Sep 25, 2024

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

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference
  • Add CHANGELOG entry for user facing changes

@ganeshnj ganeshnj requested review from a team as code owners September 25, 2024 08:44
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Sep 25, 2024

Datadog Report

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

βœ… 0 Failed, 3473 Passed, 0 Skipped, 3m 35.42s Total Time
πŸ”» Test Sessions change in coverage: 2 decreased, 5 increased, 7 no change

πŸ”» Code Coverage Decreases vs Default Branch (2)

  • test DatadogInternalTests tvOS 79.51% (-0.04%) - Details
  • test DatadogRUMTests iOS 81.09% (-0.02%) - Details

Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

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

The flush is a sync method:

/// Flushes asynchronous operations related to events write, context and message bus propagation in this instance of the SDK
/// with **blocking the caller thread** till their completion.

We should not block the user thread here, the flush method is mostly used for testing.
Instead, it might be sufficient to just publish the new consent before doing the migration. Or to call the migration from the context queue, also after publishing the new consent.

I would also be great to have a test case covering this, to prevent regression.

@ganeshnj ganeshnj force-pushed the ganeshnj/fix/consent-migration branch from 7a2ce97 to 988a354 Compare September 25, 2024 12:58
@ganeshnj ganeshnj changed the title RUM-3175 fix: flush all features before changing the consent RUM-3175 fix: force events flushing by performing consent change on context queue Sep 30, 2024
@ganeshnj ganeshnj force-pushed the ganeshnj/fix/consent-migration branch from 071fdd3 to c765a57 Compare September 30, 2024 13:47
mariedm
mariedm previously approved these changes Sep 30, 2024
@ncreated ncreated self-assigned this Nov 6, 2024
@ncreated ncreated marked this pull request as draft November 6, 2024 08:39
this prevents loss of events recorded on the current thread (right
before the consent was changed).
@ncreated ncreated force-pushed the ganeshnj/fix/consent-migration branch from 817a0e1 to 1cdb2a9 Compare November 6, 2024 12:46
@ncreated ncreated changed the title RUM-3175 fix: force events flushing by performing consent change on context queue RUM-3175 fix: Fix race condition during consent change (pending β†’ granted) Nov 6, 2024
@ncreated
Copy link
Member

ncreated commented Nov 6, 2024

(...) 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 ncreated requested review from maxep and mariedm November 6, 2024 13:03
@ncreated ncreated marked this pull request as ready for review November 6, 2024 13:03
Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

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

Nice, on target 🎯 πŸ˜‰

@ncreated
Copy link
Member

ncreated commented Nov 6, 2024

/merge

@dd-devflow
Copy link

dd-devflow bot commented Nov 6, 2024

πŸš‚ MergeQueue: pull request added to the queue

The median merge time in develop is 29m.

Use /merge -c to cancel this operation!

@dd-devflow
Copy link

dd-devflow bot commented Nov 6, 2024

🚨 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:

  • repository configuration requires approval by code owners, but no code owner approved this PR
  • target branch of PR is restricted to only allow up-to-date branches, but the pr is now outdated
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
Copy link
Member

ncreated commented Nov 6, 2024

/merge

@dd-devflow
Copy link

dd-devflow bot commented Nov 6, 2024

πŸš‚ 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
Copy link

dd-devflow bot commented Nov 6, 2024

πŸš‚ MergeQueue: pull request added to the queue

The median merge time in develop is 29m.

Use /merge -c to cancel this operation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants