-
Notifications
You must be signed in to change notification settings - Fork 199
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
fix(Analytics): Making PinpointEndpointProfile thread safe. #3457
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #3457 +/- ##
==========================================
- Coverage 68.13% 68.06% -0.08%
==========================================
Files 1085 1085
Lines 36248 36248
==========================================
- Hits 24699 24671 -28
- Misses 11549 11577 +28
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we're calling addUserId(_:)
, addUserProfile(_:)
, and setAPNsToken(_:)
ourselves (hidden behind SPI) from async contexts and Task
s.
It's my understanding that the use of the DispatchQueue
here, in particular with sync
and .barrier
, can violate the forward progress expectations of structured concurrency.
Can we turn the PinpointEndpointProfile
class into an actor, update some callsites to await
these methods, and call it a day?
f349a71
to
604bbde
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I think you're missing one change for the unit tests to pass.
diff --git a/AmplifyPlugins/Analytics/Tests/AWSPinpointAnalyticsPluginUnitTests/AWSPinpointAnalyticsPluginClientBehaviorTests.swift b/AmplifyPlugins/Analytics/Tests/AWSPinpointAnalyticsPluginUnitTests/AWSPinpointAnalyticsPluginClientBehaviorTests.swift
index 9a0529e26..0c7bad83f 100644
--- a/AmplifyPlugins/Analytics/Tests/AWSPinpointAnalyticsPluginUnitTests/AWSPinpointAnalyticsPluginClientBehaviorTests.swift
+++ b/AmplifyPlugins/Analytics/Tests/AWSPinpointAnalyticsPluginUnitTests/AWSPinpointAnalyticsPluginClientBehaviorTests.swift
@@ -57,7 +57,7 @@ class AWSPinpointAnalyticsPluginClientBehaviorTests: AWSPinpointAnalyticsPluginT
plan: testPlan,
location: testLocation,
properties: testProperties)
- let expectedEndpointProfile = PinpointEndpointProfile(applicationId: "appId",
+ var expectedEndpointProfile = PinpointEndpointProfile(applicationId: "appId",
endpointId: "endpointId")
expectedEndpointProfile.addUserId(testIdentityId)
expectedEndpointProfile.addUserProfile(userProfile)
@@ -108,7 +108,7 @@ class AWSPinpointAnalyticsPluginClientBehaviorTests: AWSPinpointAnalyticsPluginT
plan: testPlan,
location: testLocation,
properties: testProperties)
- let expectedEndpointProfile = PinpointEndpointProfile(applicationId: "appId",
+ var expectedEndpointProfile = PinpointEndpointProfile(applicationId: "appId",
endpointId: "endpointId")
expectedEndpointProfile.addUserId(testIdentityId)
expectedEndpointProfile.addUserProfile(userProfile)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Issue #
Description
This PR makes the
PinpointEndpointProfile
astruct
to prevent race conditions crashes when two differentidentifyUser
invocations attempt to modify it.General Checklist
Given When Then
inline code documentation and are named accordinglytestThing_condition_expectation()
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.