I've implemented a custom system extension VPN for macOS, using Packet Tunnel Provider.
I have a XPC connection, from the containing app to the (system) extension. What is the expected behavior after the Mac's sleep/wake? Will the same XPC remain valid? Should I start a new connection?
XPC is not directly affected by system sleep. The one place where sleep might be relevant is if the act of sleeping the system causes the XPC listener to terminate.
I recommend that you handle this as you would any other XPC service, that is, watch for interruption and invalidation:
-
An interruption is where the XPC remote peer has terminated [1] but things are set up such that you can continue to talk to it. You typically see this when talking to a daemon or agent that’s terminated by the system in response to memory pressure. In response you throw away that specific XPC connection and open a new one the next time you need to use the service.
-
An invalidation is where the XPC remote peer is no longer valid. Retrying won’t help in this case. You typically see this when the daemon or agent you’re talking to is uninstalled.
There’s an extensive discussion of these concepts in the xpc_connection_create
man page. And while the various XPC APIs differ in the details, these high-level concepts apply to them all.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Well, it can happen in other cases too, for example, if the remote peer just cancels the connection. However, your response is the same in all cases.