Skip to content

fix: prevent background task id leak - #529

Open
winshaurya wants to merge 1 commit into
amplitude:mainfrom
winshaurya:fix/background-task-leak
Open

fix: prevent background task id leak#529
winshaurya wants to merge 1 commit into
amplitude:mainfrom
winshaurya:fix/background-task-leak

Conversation

@winshaurya

@winshaurya winshaurya commented Aug 2, 2026

Copy link
Copy Markdown

Summary

@sojingle

Description

This PR fixes a bug in Amplitude.m that can lead to leaked UIBackgroundTaskIdentifiers and subsequent watchdog termination crashes (0x8badf00d), particularly when Amplitude is used inside App Extensions.

Changes Made:

  • In endBackgroundTaskIfNeeded, if [AMPUtils getSharedApplication] returns nil (which happens in extensions), the method was previously exiting early without resetting _uploadTaskID.
  • Modified the logic to ensure _uploadTaskID = UIBackgroundTaskInvalid is always executed, clearing the dangling state even if UIApplication is unavailable to formally end the task.
  • Prevents subsequent SDK operations from assuming an invalid background task is still active.

PS: 1st pr in the Amplitude Org

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

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.

1 participant