FileHandle over XPC failure?

2024-06-04 15:17:59.618853+0100 ProxyAgent[20233:29237510] [xpc.exceptions] <NSXPCConnection: 0x60000331cb40> connection from pid 20227 on anonymousListener or serviceListener: Exception caught during decoding of received selector newFlowWithIdentifier:to:type:metadata:socket:, dropping incoming message.
Exception: Exception while decoding argument 4 (#6 of invocation):
<NSInvocation: 0x600001778780>
return value: {v} void
target: {@} 0x0
selector: {:} null
argument 2: {@} 0x6000017787c0
argument 3: {@} 0x60000002d170
argument 4: {q} 1
argument 5: {@} 0x600001746600
argument 6: {@} 0x0

Exception: decodeObjectForKey: Object of class "NSFileHandle" returned nil from -initWithCoder: while being decoded for key <no key>

The extension is in Swift; the recipient is in ObjC (wheeeeee).

Based on the extension's logging, the FileHandle is not nil.

I am trying to pass a FileHandle based on a socketpair up to the user-land code. The sockets are created happily.

Any ideas what's going wrong here?

Oh, also, I am somehow causing sysextd to die often:

Termination Reason:    Namespace SIGNAL, Code 4 Illegal instruction: 4
Terminating Process:   exc handler [20261]

Thread 0 Crashed::  Dispatch queue: sysextd.extension_manager
0   sysextd                       	       0x105fb8217 0x105f5d000 + 373271
1   sysextd                       	       0x105f94340 0x105f5d000 + 226112
2   sysextd                       	       0x105f94036 0x105f5d000 + 225334
3   sysextd                       	       0x105f9749e 0x105f5d000 + 238750
4   sysextd                       	       0x105f93df7 0x105f5d000 + 224759
5   sysextd                       	       0x105f93c01 0x105f5d000 + 224257
6   sysextd                       	       0x105f93e78 0x105f5d000 + 224888
7   Foundation                    	    0x7ff80c04d018 __NSXPCCONNECTION_IS_CALLING_OUT_TO_EXPORTED_OBJECT_S1__ + 10
8   Foundation                    	    0x7ff80bff76e8 -[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] + 2347
9   Foundation                    	    0x7ff80bfae2ce message_handler + 206
10  libxpc.dylib                  	    0x7ff80ae07ae0 _xpc_connection_call_event_handler + 56
11  libxpc.dylib                  	    0x7ff80ae068c6 _xpc_connection_mach_event + 1413
12  libdispatch.dylib             	    0x7ff80af113b1 _dispatch_client_callout4 + 9
13  libdispatch.dylib             	    0x7ff80af2a041 _dispatch_mach_msg_invoke + 445
14  libdispatch.dylib             	    0x7ff80af171cd _dispatch_lane_serial_drain + 342
15  libdispatch.dylib             	    0x7ff80af2ab77 _dispatch_mach_invoke + 484
16  libdispatch.dylib             	    0x7ff80af171cd _dispatch_lane_serial_drain + 342
17  libdispatch.dylib             	    0x7ff80af17dfd _dispatch_lane_invoke + 366
18  libdispatch.dylib             	    0x7ff80af21eee _dispatch_workloop_worker_thread + 753
19  libsystem_pthread.dylib       	    0x7ff80b0c5fd0 _pthread_wqthread + 326
20  libsystem_pthread.dylib       	    0x7ff80b0c4f57 start_wqthread + 15

My general advice is that you test this stuff using XPC loopback, because that radically simplifies the debugging experience. See TN3113 Testing and debugging XPC code with an anonymous listener for info on how I set this up.

Can you reproduce this with a XPC loopback?


Oh, also, I am somehow causing sysextd to die often:

Please create a separate thread for that. Include the full crash report, per the advice in Posting a Crash Report. Put it in the App & System Services > Core OS subtopic so that I see it.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

My (much smaller) test TPP app was able to do the FileHandle passing, but the (much bigger) real app wasn't. So I know it's possible, but also just as clearly I'm doing something wrong. Somewhere. :)

To help you focus your search, I looked at how -[NSFileHandler initWithCoder:] is implemented and I can only see one way for it to return nil, namely, it calls -decodeXPCObjectOfType:forKey: to get an XPC object of type XPC_TYPE_FD and that fails.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Which fits with the parameter being nil in the dumb, but I can't figure out why that would be the case! Very frustrating.

FileHandle over XPC failure?
 
 
Q