`XPC_ERROR_CONNECTION_INTERRUPTED` doesn't appear to actually behave as documented
Closed this issue · 4 comments
After releasing 0.3.0 of SecureXPC I started updating SwiftAuthorizationSample and have run into an unexpected issue:
- Over XPC the app asks the helper tool to uninstall itself
- As part of the helper tool uninstalling itself, the helper tool terminates
- This results in the client receiving
XPC_ERROR_CONNECTION_INTERRUPTED
.
i. This is expected, Apple's documentation for interrupted says: "Will be delivered to the connection’s event handler if the remote service exited." - Installer the helper tool again (under the hood via
SMJobBless
). - The next
send
using the client results in aXPC_ERROR_CONNECTION_INVALID
i. This is unexpected, Apple's documentation for interrupted also says: "The connection is still live even in this case, and resending a message will cause the service to be launched on-demand."
ii. I can confirm the service is not launched on-demand. - The subsequent
send
using the client results in the service being launched.
i. This is not because of anything XPC is doing automatically, it's because when we receivedXPC_ERROR_CONNECTION_INVALID
in step 4 we performself.connection = nil
which means we establish a new connection on the nextsend
.
A simple way we can resolve this is to always set self.connection = nil
when we receive XPC_ERROR_CONNECTION_INTERRUPTED
.
@amomchilov thoughts on us doing this? It means we're explicitly going against Apple's documentation, but it appears their implementation is bugged and/or their documentation is incorrect.
i. This is unexpected, Apple's documentation for interrupted also says: "The connection is still live even in this case, and resending a message will cause the service to be launched on-demand."
ii. I can confirm the service is not launched on-demand.
I don't think that's unexpected. They were talking about the process merely exiting. Here's it's existing, and deleting itself.
The subsequent send using the client results in the service being launched.
Now that's what I find to be unexpected. How did the service relaunch, if it deleted itself?
The subsequent send using the client results in the service being launched.
Now that's what I find to be unexpected. How did the service relaunch, if it deleted itself?
Because I'm dumb and wrote the repro steps wrong, missing a key step. I've revised it now to reflect what I was actually doing. This is now step 4:
- Installer the helper tool again (under the hood via SMJobBless).
Haahaha that makes quite a difference, doesn't it!
May I suggest renaming this issue to:
XPC_ERROR_CONNECTION_INTERRUPTED
misbehaves when re-installing a service