Skip to content

v4.0.4 - Using threadsafe dictionaries to avoid race condition accessing udpat…#101

Merged
PravinPK merged 5 commits intoadobe:dev-v4.0.4from
PravinPK:dev-v4.0.4
May 19, 2024
Merged

v4.0.4 - Using threadsafe dictionaries to avoid race condition accessing udpat…#101
PravinPK merged 5 commits intoadobe:dev-v4.0.4from
PravinPK:dev-v4.0.4

Conversation

@PravinPK
Copy link
Copy Markdown

Description

Fix for crash could occurs when updateProposition is called recursively

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@PravinPK PravinPK changed the title Using threadsafe dictionaries to avoid race condition accessing udpat… v4.0.4 - Using threadsafe dictionaries to avoid race condition accessing udpat… May 18, 2024
Copy link
Copy Markdown
Contributor

@spoorthipujariadobe spoorthipujariadobe left a comment

Choose a reason for hiding this comment

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

LGTM. Since we're doing remove all in a bunch of places, might be easy to make a method witch accepts the dictionary and loops through the keys removing each, but it's just a NIT

private func updateCachedPropositions(for requestedScopes: [DecisionScope]) {
// update cache with accumulated propositions
cachedPropositions.merge(propositionsInProgress) { _, new in new }
cachedPropositions.merge(propositionsInProgress.shallowCopy) { _, new in new }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you check if cachedPropositions dict is accessed from different threads? If so, can you make it thread safe?

event.isPersonalizationDecisionResponse,
let requestEventId = event.requestEventId,
updateRequestEventIdsInProgress.contains(where: { $0.key == requestEventId })
updateRequestEventIdsInProgress.shallowCopy.contains(where: { $0.key == requestEventId })
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: Instead of shallowCopy, use the ThreadSafeDictionary.first(...) method

@codecov
Copy link
Copy Markdown

codecov bot commented May 19, 2024

Codecov Report

Attention: Patch coverage is 76.47059% with 8 lines in your changes are missing coverage. Please review.

Please upload report for BASE (dev-v4.0.4@3c7250e). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-v4.0.4     #101   +/-   ##
=============================================
  Coverage              ?   97.21%           
=============================================
  Files                 ?       13           
  Lines                 ?      861           
  Branches              ?        0           
=============================================
  Hits                  ?      837           
  Misses                ?       24           
  Partials              ?        0           
Files Coverage Δ
Sources/AEPOptimize/Optimize.swift 96.28% <76.47%> (ø)

@PravinPK PravinPK merged commit db339f5 into adobe:dev-v4.0.4 May 19, 2024
// Removing all the values from thread-safe dictionary
// TODO: Introduce removeAll method to ThreadSafeDictionary in AEPCore
for key in propositionsInProgress.keys {
_ = propositionsInProgress.removeValue(forKey: key)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is there an edge case where another thread is adding another entry while we are removing the all in here?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants