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

Concurrent Modification Fix #362

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 24.7.8
* Mitigated an issue where visibility could have been wrongly assigned if a view was closed while going to background. (Experimental!)
* Mitigated an issue where the user provided URLSessionConfiguration was not applied to direct requests
* Mitigated an issue where a concurrent modification error could have happen when starting multiple stopped views

## 24.7.7
* Changed the visibility tracking segmentation values to binary
Expand Down
26 changes: 16 additions & 10 deletions CountlyViewTrackingInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -545,27 +545,33 @@ - (void)startStoppedViewsInternal
{
// Create an array to store keys for views that need to be removed
NSMutableArray<NSString *> *keysToRemove = [NSMutableArray array];

NSMutableArray<NSString *> *keysToStart = [NSMutableArray array];

// Collect keys without modifying the dictionary
[self.viewDataDictionary enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, CountlyViewData * _Nonnull viewData, BOOL * _Nonnull stop) {
if (viewData.willStartAgain)
{
NSString *viewID = [self startViewInternal:viewData.viewName customSegmentation:viewData.startSegmentation isAutoStoppedView:viewData.isAutoStoppedView];

// Retrieve the newly created viewData for the viewID
CountlyViewData* viewDataNew = self.viewDataDictionary[viewID];

// Copy the segmentation data from the old view to the new view
viewDataNew.segmentation = viewData.segmentation.mutableCopy;

// Add the old view's ID to the array for removal later
[keysToStart addObject:key];
[keysToRemove addObject:viewData.viewID];
}
}];

// Start the collected views after enumeration
for (NSString *key in keysToStart)
{
CountlyViewData *viewData = self.viewDataDictionary[key];
NSString *viewID = [self startViewInternal:viewData.viewName customSegmentation:viewData.startSegmentation isAutoStoppedView:viewData.isAutoStoppedView];

// Retrieve and update the newly created viewData
CountlyViewData *viewDataNew = self.viewDataDictionary[viewID];
viewDataNew.segmentation = viewData.segmentation.mutableCopy;
}

// Remove the entries from the dictionary
[self.viewDataDictionary removeObjectsForKeys:keysToRemove];
}


- (void)stopAllViewsInternal:(NSDictionary *)segmentation
{
// TODO: Should apply all the segmenation operations here at one place instead of doing it for individual view
Expand Down
Loading