15 Replies
      Latest reply: Jan 11, 2017 10:23 PM by ninja31312 RSS
      ninja31312 Level 1 Level 1 (0 points)

        We encountered a large number of crashes about XPC reported by our tool, but we could not reproduce it.

        All we know is that

        - App crashes on iOS8 or iOS9.

        - App crashes while it backed from background to foreground.

        - There are something happened between com.apple.nsurlsessiond and our app.

         

        Here is the crash log.

         

        Date/Time: 2016-04-21T17:32:24Z
        OS Version: iPhone OS 9.2.1 (13D15)
        Report Version: 104
        Exception Type: SIGABRT
        Exception Codes: #0 at 0x18107c140
        Crashed Thread: 0
        Application Specific Information: *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
        reason: '*** -[_NSXPCDistantObject methodSignatureForSelector:]: No protocol has been set on connection <NSXPCConnection: 0x1471921a0> connection to service named com.apple.nsurlsessiond'
        Last Exception Backtrace: 0
        CoreFoundation 0x00000001814d9900 __exceptionPreprocess + 124 1 
        libobjc.A.dylib 0x0000000180b47f80 objc_exception_throw + 56 2 
        CoreFoundation 0x00000001814d9848 +[NSException raise:format:] + 120 3 
        Foundation 0x0000000181dace7c -[_NSXPCDistantObject methodSignatureForSelector:] + 376 4 
        CoreFoundation 0x00000001814dd324 ___forwarding___ + 212 5 
        CoreFoundation 0x00000001813e168c _CF_forwarding_prep_0 + 92 6 
        CoreFoundation 0x000000018147efc4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 7 
        CoreFoundation 0x000000018147e7e4 _CFXRegistrationPost + 396 8 
        CoreFoundation 0x000000018147e564 ___CFXNotificationPost_block_invoke + 60 9 
        CoreFoundation 0x00000001814e3de4 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1532 10 
        CoreFoundation 0x00000001813bf0f4 _CFXNotificationPost + 368 11 
        Foundation 0x0000000181daed2c -[NSNotificationCenter postNotificationName:object:userInfo:] + 68 12 
        UIKit 0x000000018644f9f8 -[UIApplication _sendWillEnterForegroundCallbacks] + 264 13 
        UIKit 0x0000000186489988 -[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:] + 1752 14 
        UIKit 0x0000000186489038 -[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:] + 448 15 
        UIKit 0x0000000186473588 __70-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 152 16 
        UIKit 0x0000000186473210 -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:] + 712 17 
        FrontBoardServices 0x0000000182a8f790 -[FBSSerialQueue _performNext] + 184 18 
        FrontBoardServices 0x0000000182a8fb10 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 19 
        CoreFoundation 0x0000000181490efc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 20 
        CoreFoundation 0x0000000181490990 __CFRunLoopDoSources0 + 540 21 
        CoreFoundation 0x000000018148e690 __CFRunLoopRun + 724 22 
        CoreFoundation 0x00000001813bd680 CFRunLoopRunSpecific + 384 23
        GraphicsServices 0x00000001828cc088 GSEventRunModal + 180 24 
        UIKit 0x0000000186234d90 UIApplicationMain + 204 25
        
        

         

        Does anyone know the root cause of this crash ?

        • Re: Foundation in -[_NSXPCDistantObject methodSignatureForSelector:]
          eskimo Apple Staff Apple Staff (6,480 points)

          By an amazing coincidence I’ve been working with another developer (s. 639,485,677) who has bumped into this problem.  At this point my best guess is that this is a bug in NSURLSession’s background session support.  I believe it’s been around for a while (since NSURLSession background sessions were introduced in iOS 7) but folks seem to be hitting it more often now.

          I’ve asked my other developer to file a bug report about this, but I haven’t yet heard back from them, so I’m going to ask you to do the same: please file a bug report about this then post your bug number here.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: Foundation in -[_NSXPCDistantObject methodSignatureForSelector:]
              ninja31312 Level 1 Level 1 (0 points)

              I created a bug report 25899758 for this issue. Thank you for your help !

              • Re: Foundation in -[_NSXPCDistantObject methodSignatureForSelector:]
                robotive Level 1 Level 1 (0 points)

                Hi,

                 

                we have started to get lots of these (or maybe similar) crashes recently (now it's our #2 top crash).

                 

                Do you think this is related?

                 

                Crashed: com.apple.main-thread
                0  libobjc.A.dylib                0x182165b90 objc_msgSend + 16
                1  CoreFoundation                 0x182af945c -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1604
                2  CoreFoundation                 0x1829ce6c8 _CFXNotificationPost + 368
                3  Foundation                     0x1833d680c -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
                4  UIKit                          0x187efb214 __47-[UIApplication _applicationDidEnterBackground]_block_invoke + 320
                5  UIKit                          0x187fcb6d4 +[UIViewController _performWithoutDeferringTransitions:] + 128
                6  UIKit                          0x187efb080 -[UIApplication _applicationDidEnterBackground] + 100
                7  UIKit                          0x187efb6fc -[UIApplication _handleApplicationDeactivationWithScene:shouldForceExit:transitionContext:completion:] + 948
                8  UIKit                          0x187f0ba80 -[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:] + 448
                9  UIKit                          0x187ef570c __70-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 152
                10 UIKit                          0x187ef5394 -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:] + 712
                11 FrontBoardServices             0x18448f7ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
                12 FrontBoardServices             0x18448f618 -[FBSSerialQueue _performNext] + 168
                13 FrontBoardServices             0x18448f9c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
                14 CoreFoundation                 0x182aa509c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
                15 CoreFoundation                 0x182aa4b30 __CFRunLoopDoSources0 + 540
                16 CoreFoundation                 0x182aa2830 __CFRunLoopRun + 724
                17 CoreFoundation                 0x1829ccc50 CFRunLoopRunSpecific + 384
                18 GraphicsServices               0x1842b4088 GSEventRunModal + 180
                19 UIKit                          0x187cb6088 UIApplicationMain + 204
                20 tado                           0x10007d004 main (AppDelegate.swift:14)
                21 libdispatch.dylib              0x18256a8b8 (Missing)
                

                 

                Thanks a lot.

                  • Re: Foundation in -[_NSXPCDistantObject methodSignatureForSelector:]
                    eskimo Apple Staff Apple Staff (6,480 points)

                    ninja31312 wrote:

                    I created a bug report 25899758 for this issue.

                    Thanks.  By now you’ll know that your bug was closed as a dup of another bug (r. 24449114).  I had cause to dig into that bug and I believe that I know what’s going on.  I forgot to loop back here to post an update; sorry.

                    AFAICT this crash is caused by NSURLSession’s background session support.  This passes work to its daemon (nsurlsessiond) using NSXPCConnection (not part of the iOS SDK, but public API on OS X, so you can read up about it there).  NSXPCConnection has the notion of interrupted connections, that is, the IPC connection between the client and the server has torn but can be re-established.  NSURLSession’s background session support, like all NSXPCConnection clients, must handle these interruptions as a matter of course.

                    Alas, there’s a bug in the way it does that.  This bug is a race condition that manifest itself as this crash.  We hope to fix this in a future OS release but I can’t share any concrete details.


                    robotive wrote:

                    Do you think this is related?

                    No.  The above-mentioned crash is specific to NSXPCConnection based on the No protocol has been set on connection message.  Your case looks like a standard ‘dangling notification’ problem, that is, some object has registered for a UIApplicationDidEnterBackgroundNotification and then been deallocated without unregistering.

                    Share and Enjoy

                    Quinn “The Eskimo!”
                    Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                    let myEmail = "eskimo" + "1" + "@apple.com"

                    WWDC runs Mon, 13 Jun through to Fri, 17 Jun.  During that time all of DTS will be at the conference, helping folks out face-to-face. http://developer.apple.com/wwdc/

                • Re: Foundation in -[_NSXPCDistantObject methodSignatureForSelector:]
                  morimoto Level 1 Level 1 (0 points)

                  We were able to resolve this issue simply by switching to ephemeralSessionConfiguration in-place:

                  NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];

                   

                  An obvious fix in hindsight, but when we found our crash, with code we weren't familiar with, it wasn't clear.

                  Hope this helps some others shortcut if they are able to use it.

                  • Re: Foundation in -[_NSXPCDistantObject methodSignatureForSelector:]
                    gilmeroz Level 1 Level 1 (0 points)

                    Is there any solution for iOS9 users? ephemeralSessionConfiguration is available from iOS10+