Skip to content

Commit

Permalink
Merge pull request #71 from trilemma-dev/interrupted-client
Browse files Browse the repository at this point in the history
Always sets connection to nil when interrupted
  • Loading branch information
jakaplan authored Jan 27, 2022
2 parents fda1e98 + 2f7df97 commit a96f1d3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Sources/SecureXPC/Client/XPCClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,14 @@ public class XPCClient {
// Will be delivered to the connection’s event handler if the remote service exited. The connection is
// still live even in this case, and resending a message will cause the service to be launched on-demand.
//
// While Apple's documentation is technically correct, it's misleading in the case of an anonymous
// connection where there is no service. Because there is no service, there is nothing to be relaunched
// on-demand. The connection might technically still be alive, but resending a message will *not* work.
// From observed behavior Apple's documentation is *not* correct. After the connection is interrupted the
// subsequent call will result in XPC_ERROR_CONNECTION_INVALID and the service will not be relaunched. See
// https://github.com/trilemma-dev/SecureXPC/issues/70 for more details and discussion.
//
// By setting the connection to `nil` when there is no service (indicated by no service name), anonymous
// clients can throw a useful specific error when `createConnection()` is called.
if self.serviceName == nil {
self.connection = nil
}
// Additionally, in the case of an anonymous connection there is no service. Because there is no service,
// there is nothing to be relaunched on-demand. The connection might technically still be alive, but
// resending a message will *not* work.
self.connection = nil
}

// XPC_ERROR_TERMINATION_IMMINENT is not applicable to the client side of a connection
Expand Down

0 comments on commit a96f1d3

Please sign in to comment.