Incorrect error reported: Can't end BackgroundTask

Originator:pzabelin
Number:rdar://FB7573876 Date Originated:Feb 11, 2020 at 9:15 AM
Status:Fixed Resolved:iOS 13.4 beta 1
Product:iOS SDK Product Version:13.1
Classification: Reproducible:Always
 
Basic information
Please provide a descriptive title for your feedback:

Incorrect error reported: Can't end BackgroundTask


Which area are you seeing an issue with?
Simulator

What type of feedback are you reporting?
Incorrect/Unexpected Behavior


Description
Please describe the issue:
When I background my app in the simulator, I see this message in the console:

Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.


Please list the steps you took to reproduce the issue:
1. Create an empty Single View iOS app in Xcode
2. Run app in iOS Simulator
3. Background the app (Cmd-H)
4. See the message in the Xcode debugger output.


What did you expect to happen?
Expect no error message, as it makes very difficult to debug unbalanced calls to the real background task within the app.


What actually happened?
Every time app goes to the background I see the error message:

Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

and I was able to set the breakpoint in UIApplicationEndBackgroundTaskError() as suggested and see the stack trace:

#0	0x00007fff480b1334 in UIApplicationEndBackgroundTaskError ()
#1	0x00007fff480b15d5 in -[UIApplication _endBackgroundTask:] ()
#2	0x0000000101658d48 in _dispatch_client_callout ()
#3	0x000000010165bcb9 in _dispatch_block_invoke_direct ()
#4	0x00007fff3662237e in __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ ()
#5	0x00007fff3662206c in -[FBSSerialQueue _queue_performNextIfPossible] ()
#6	0x00007fff3662257b in -[FBSSerialQueue _performNextFromRunLoopSource] ()
#7	0x00007fff23bd4471 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#8	0x00007fff23bd439c in __CFRunLoopDoSource0 ()
#9	0x00007fff23bd3b74 in __CFRunLoopDoSources0 ()
#10	0x00007fff23bce87f in __CFRunLoopRun ()
#11	0x00007fff23bce066 in CFRunLoopRunSpecific ()
#12	0x00007fff384c0bb0 in GSEventRunModal ()
#13	0x00007fff48092d4d in UIApplicationMain ()
#14	0x0000000101331b4b in main at

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!