Skip to content

fix(ios): replace sleep(5) in applicationWillTerminate with bounded wait - #400

Open
vaibhavppandey wants to merge 1 commit into
Dev-hwang:masterfrom
vaibhavppandey:fix/ios-will-terminate-watchdog
Open

vaibhavppandey wants to merge 1 commit into
Dev-hwang:masterfrom
vaibhavppandey:fix/ios-will-terminate-watchdog

Conversation

@vaibhavppandey

Copy link
Copy Markdown

Fixes #399

Replaces the fixed sleep(5) in applicationWillTerminate with a wait on the actual onDestroy reply, capped at 2s. While waiting, the main run loop keeps running so the reply and any platform-channel calls from onDestroy can be handled.

  • ForegroundTask.destroy() / BackgroundService.run() take an optional onDestroyed callback, fired when Dart onDestroy replies, or immediately when there is nothing to wait for.
  • No Dart or public API changes; stopService is unchanged.

Tested (example app, iOS 18.7.8, profile build, swiped away from the app switcher):

before after
onDestroy ran +0.19s +0.11s
process exited +5.21s +0.28s

Copilot AI lite review requested due to automatic review settings September 25, 2026 13:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

One or more issues must be addressed before approval.

Review effort: Lite
Findings: None

What changed in this PR

Replaces iOS termination’s fixed five-second sleep with a bounded, run-loop-responsive wait for Dart onDestroy completion.

Changes:

  • Adds destruction completion callbacks through the service layers.
  • Waits up to two seconds while processing the main run loop.
File Description
ios/​flutter_foreground_task/​Sources/​flutter_foreground_task/​SwiftFlutterForegroundTaskPlugin.swift Updated as part of this pull request.
ios/​flutter_foreground_task/​Sources/​flutter_foreground_task/​service/​ForegroundTask.swift Updated as part of this pull request.
ios/​flutter_foreground_task/​Sources/​flutter_foreground_task/​service/​BackgroundService.swift Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@vaibhavppandey

Copy link
Copy Markdown
Author

@Dev-hwang could you please review this PR? It fixes #399 (iOS apps getting killed with 0x8BADF00D when terminated while the service is running). Tested on device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] sleep(5) in applicationWillTerminate exceeds the 5s termination budget (0x8BADF00D)

2 participants