Skip to content

Commit 29ce8ad

Browse files
nan-licursoragent
andcommitted
fix: stop mutating deltaQueue during flush iteration
Rebuilding the unmatched list avoids for-in + remove(at:) on the same array, which could crash or skip deltas. Co-Authored-By: Cursor <cursoragent@cursor.com>
1 parent 5be86ab commit 29ce8ad

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,16 @@ public class OSOperationRepo: NSObject {
151151
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSOperationRepo flushDeltaQueue in background: \(inBackground) with queue: \(self.deltaQueue)")
152152
}
153153

154-
var index = 0
154+
var unmatched: [OSDelta] = []
155155
for delta in self.deltaQueue {
156156
if let executor = self.deltasToExecutorMap[delta.name] {
157157
executor.enqueueDelta(delta)
158-
self.deltaQueue.remove(at: index)
159158
} else {
160-
// keep in queue if no executor matches, we may not have the executor available yet
161-
index += 1
159+
// Keep if no executor matches yet (module may not have started).
160+
unmatched.append(delta)
162161
}
163162
}
163+
self.deltaQueue = unmatched
164164

165165
// Persist the deltas (including removed deltas) to storage after they are divvy'd up to executors.
166166
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_OPERATION_REPO_DELTA_QUEUE_KEY, withValue: self.deltaQueue)

0 commit comments

Comments
 (0)