Repository navigation
Conversation
iOS kills an app with 0x2182BAD2 when a background task stays open past the 30 s limit or gets orphaned by a second begin with the same name. Legacy focus processors stay unchanged because Sessions V2 replaces them. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Cap every background task at 20 s off the main thread and track all open tasks per name in
OSBackgroundTaskHandlerImpl. SDK-5784, fixes #1814.Details
Motivation
iOS kills an app with
0x2182BAD2when a background task stays open past the 30 s limit. Before this change,OSBackgroundTaskHandlerImplstored only 1UIBackgroundTaskIdentifierper task name, so a second begin under the same name orphaned the first task. Task expiry also required the main thread, so a busy main thread left tasks open until RunningBoard killed the process.Scope
OSBackgroundTaskHandlerImplkeeps every open task per name, passes the task name to UIKit logs, ends each task at most once, and ends open tasks onsetTaskInvalid:.QOS_CLASS_UTILITYso stalled tasks end off the main thread inside the 30 s allowance.OSAttributedFocusTimeProcessor,OSUnattributedFocusTimeProcessor, andOSBaseFocusTimeProcessor) stay unchanged because Sessions V2 (FeatureFlag.sdkSessionsV2ApiCutover) replaces them. Until cutover finishes, the 20 s handler cap endsSESSION_OUTCOMES_TASKbefore its 30 s timer fires. iOS suspends the app cleanly, and savedunsentActiveTimeretries on the next open.Testing
Unit testing
8 unit tests in
OSBackgroundTaskHandlerImplTestscover task names,UIBackgroundTaskInvalid, repeated begins per name, per-ID expiry,setTaskInvalid:, off-main-thread timeouts, early cancellation, and synchronous expiry races. RanOSBackgroundTaskHandlerImplTests,OneSignalTrackerTests, andOneSignalNewSessionTests(19 tests total) on an iPhone 17 Pro simulator (iOS 26.5) with 0 failures, plusswiftlintwith 0 violations.Manual testing
Not run on a physical device or full test plan for this revised scope.
Affected code checklist
Checklist
Overview
Testing
Final pass