chore: Add coordinator to prevent push delivery metrics loss#951
chore: Add coordinator to prevent push delivery metrics loss#951mahmoud-elmorabea wants to merge 1 commit intomainfrom
Conversation
Sample app builds 📱Below you will find the list of the latest versions of the sample apps. |
SDK binary size reports 📊SDK binary size of this PRSDK binary size diff report vs. main branch |
| } else { | ||
| // Fallback to original behavior if no coordinator | ||
| RichPushRequestHandler.shared.stopAll() | ||
| } |
There was a problem hiding this comment.
Bug: Stale Coordinator Causes Incorrect Timeout Handling
The currentCoordinator isn't cleared when autoTrackPushEvents is false or after a coordinator successfully completes its operations. This can cause serviceExtensionTimeWillExpire() to operate on a stale coordinator from a previous push, leading to incorrect timeout handling, and may also result in unnecessary memory usage.
There was a problem hiding this comment.
this looks like a valid concern, we should set currentCoordinator = nil on didRecieve
Shahroz16
left a comment
There was a problem hiding this comment.
i think we need to add tests for this Coordinator race/timeout cases.
| } else { | ||
| // Fallback to original behavior if no coordinator | ||
| RichPushRequestHandler.shared.stopAll() | ||
| } |
There was a problem hiding this comment.
this looks like a valid concern, we should set currentCoordinator = nil on didRecieve
There was a problem hiding this comment.
i still see a reference in MessagingInApp can we remove that too, please
| private func callContentHandler(with content: UNNotificationContent, reason: String) { | ||
| logger.info("NSE operations complete (\(reason)). Calling content handler.") | ||
|
|
||
| contentHandler(content) |
There was a problem hiding this comment.
should this be done on main thread? did you check with wrappers? they often require NSE operation to be done on main
Why?
Some delivery metrics are lost because we don't wait for that request to finish. The previous implementation had two independent async operations (metrics tracking and rich push processing) and only rich push processing called
contentHandlerupon completion. When rich push is faster, it would callcontentHandlerand terminate the NSE, killing the in-flight metrics request even when plenty of NSE time remained.How we solve?
Add
NSEOperationCoordinatorto wait for both async calls or NSE call that it will expire. The coordinator ensurescontentHandleris called exactly once only after:serviceExtensionTimeWillExpireis called by iOSThis maximizes delivery metrics success by using the full available NSE execution time instead of terminating prematurely when only one operation completes.
Note: Moved
Synchronized<T>utility to Common module for reuse