-
Notifications
You must be signed in to change notification settings - Fork 369
fix(ios): a linger sleeper may not close a window it does not own #519
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
Closed
KesleyDavid
wants to merge
1
commit into
milind-soni:main
from
KesleyDavid:KesleyDavid/ios-linger-generation
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🌐 Web query:
For the repository's supported iOS deployment targets, can UIApplication.beginBackgroundTask(withName:expirationHandler:) return UIBackgroundTaskIdentifier.invalid while the process can still execute the 25-second Swift Task.sleep, and should the caller still run its cleanup fallback?💡 Result:
Yes, UIApplication.beginBackgroundTask(withName:expirationHandler:) can return UIBackgroundTaskIdentifier.invalid, even while your app process is still active and capable of executing code like Task.sleep [1][2][3]. When this method returns UIBackgroundTaskIdentifier.invalid, it indicates that the system is unable to grant the request for additional background execution time [1][2][3]. This typically happens if the system is under heavy resource pressure or if the app is already in a state where background execution is not permitted [2][3]. If the method returns an invalid identifier, you have not been granted an assertion, and the system may suspend your app shortly after it enters the background [2][3]. In this scenario: 1. You should not rely on the background task to keep your process alive [2]. 2. You do not need to call endBackgroundTask(_:) because no valid task was created [4][5]. 3. You should still consider whether your cleanup fallback is necessary [5]. Since the background task failed, your app is at high risk of being suspended or terminated by the watchdog mechanism sooner than it would have been otherwise [2][3]. Running your cleanup logic immediately—even if the task didn't start—is a safe and often recommended practice to ensure state consistency before the system potentially suspends the application [5]. It is best practice to always check if the returned identifier is not equal to UIBackgroundTaskIdentifier.invalid before proceeding with logic that relies on the background task [4][5][6]. If it is invalid, you can treat it as an immediate signal that your background work cannot proceed, allowing you to trigger your cleanup or cancellation path immediately [5].
Citations:
🏁 Script executed:
Repository: milind-soni/OpenMausBot
Length of output: 12936
🏁 Script executed:
Repository: milind-soni/OpenMausBot
Length of output: 5053
Handle an invalid UIKit background task.
If
beginBackgroundTask(...)returns.invalid,lingerTaskstays invalid. When the 25-second sleeper resumes, the guard exits without callingdisconnect(). Disconnect immediately when the UIKit task is invalid, or track linger activity separately.🤖 Prompt for AI Agents
Source: MCP tools