Skip to content

Commit 13d214f

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 13d214f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,17 @@ 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+
// Don't mutate deltaQueue while iterating — rebuild with unmatched deltas only.
155+
var unmatched: [OSDelta] = []
155156
for delta in self.deltaQueue {
156157
if let executor = self.deltasToExecutorMap[delta.name] {
157158
executor.enqueueDelta(delta)
158-
self.deltaQueue.remove(at: index)
159159
} else {
160-
// keep in queue if no executor matches, we may not have the executor available yet
161-
index += 1
160+
// Keep if no executor matches yet (module may not have started).
161+
unmatched.append(delta)
162162
}
163163
}
164+
self.deltaQueue = unmatched
164165

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

0 commit comments

Comments
 (0)