xpc api misuse crash

To begin with: I know it's my code, because if I go back to our main branch and try it, I don't get this crash. But I can't figure out what it's unhappy about, so I'm not sure what changes I have to look for. (Also, this is macOS.)

The daemon tries to communicate with a Network Extension over XPC. I have a class, with a shared instance, and I have a cached NSXPCConnection connection instance variable. So my code is something like id connection = [[ExtensionCommunication shared] connection], which is created by [[NSXPCConnection alloc] initWithMachServiceName:self.redirectorMachServiceName options:0].

With my changes (whatever they are), when it does [_connection resume], it crashes:

  * frame #0: 0x00007ff8191ab20e libxpc.dylib`_xpc_api_misuse + 117
    frame #1: 0x00007ff8191963a1 libxpc.dylib`xpc_connection_resume + 54

This happens whether the network extension is activated or not. The crash happens the second time this is called. (Hm, one thing I need to figure out then is why my cached connection object is being set to nil. It shouldn't be. hm.)

Anyway! Any suggestions on how I can try to debug this?

Answered by kithrup in 745058022

Oh, this doe seem to have been ARC-related, although I'm not sure why it worked before. I changed my cached ivar to an @property with retain, and now it's back to not crashing, so yay!

Ok, this is totally bizarre: I just aded

    os_log_debug(self.logger, "returning cached connection %p", _connection);

to the method that handles the cached version, and now it's not crashing. Comment it out, and crash. ARC related?

Accepted Answer

Oh, this doe seem to have been ARC-related, although I'm not sure why it worked before. I changed my cached ivar to an @property with retain, and now it's back to not crashing, so yay!

xpc api misuse crash
 
 
Q