27

I'm getting a strange bug:

Fatal Exception: NSInvalidArgumentException *** -[_NSXPCDistantObject methodSignatureForSelector:]: No protocol has been set on connection connection to service named com.apple.nsurlsessiond"

This issue only appears to be happening on iOS 9. According to the stack trace, the bug is triggered by a call to -[UIApplication _sendWillEnterForegroundCallbacks].

Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 6485512008 __exceptionPreprocess
1  libobjc.A.dylib                6833323904 objc_exception_throw
2  CoreFoundation                 6485511824 -[NSException initWithCoder:]
3  Foundation                     6500536092 -[_NSXPCDistantObject methodSignatureForSelector:]
4  CoreFoundation                 6485526892 ___forwarding___
5  CoreFoundation                 6484495532 _CF_forwarding_prep_0
6  CoreFoundation                 6485141004 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
7  CoreFoundation                 6485138988 _CFXRegistrationPost
8  CoreFoundation                 6485138348 ___CFXNotificationPost_block_invoke
9  CoreFoundation                 6485554212 -[_CFXNotificationRegistrar find:object:observer:enumerator:]
10 CoreFoundation                 6484354836 _CFXNotificationPost
11 Foundation                     6500543948 -[NSNotificationCenter postNotificationName:object:userInfo:]
12 UIKit                          6577878356 -[UIApplication _sendWillEnterForegroundCallbacks]
   continues ... 

So it would appear that when the app will enter foreground, some observer registered tries to reconnect with nsurlsessiond over via RPC and fails? I do a background transfer session using NSURLSession, but I'm unable to reproduce this so I'm not sure if it's related or not.

Has anyone seen this issue before? Is there anything I can do to address it?

bcattle
  • 10,155
  • 5
  • 54
  • 73
  • 3
    There's been a lot of crash reports on iOS 9 regarding the notification center and NSInvalidArgumentException. It looks like the crash happens when the app is backgrounded and the operating system destructs the app while some data is still being processed. Not sure if it's the same bug you're facing though. – Alex Machado Nov 26 '15 at 17:41

2 Answers2

11

Looks like a bug in iOS described here: https://forums.developer.apple.com/thread/45651#140745

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.

zh.
  • 1,144
  • 1
  • 11
  • 17
  • You should really edit your answer with the contents of the link in case the link becomes invalid. As it stands, this is a link-only answer – JAL Jun 17 '16 at 16:26
0

It appears that something that has previously subscribed to UIApplicationWillEnterForeground notifications was deallocated without un-subscribing or that the expected interface is not present.

I would check for any place that your app has subscribed to that notification, and ensure that it properly un-subscribes, and that the methods referenced are implemented.

Failing on methodSignatureForSelector would indicated that the method that NSNotificationCenter wants to call with the notification is not implemented. Could be a missing method, or a typo.

Dave Lyon
  • 615
  • 5
  • 8
  • Thanks for the answer. The issue is that I don't use `UIApplicationWillEnterForeground`, rather it appears to be something Apple is using internally due to the exception text that mentions `nsurlsessiond`. – bcattle Jun 15 '16 at 21:53