Xpc client waiting for service up indication.

My installer load XPC service and XPC client that attempt to call remote xpc method on that service.

However, the service my be loaded arbitrarily and the client may get invalid connection since the service hasn't loaded yet.

So far I haven't found any way get service-load indication, so I'm calling the retry method recursively from within the connection invalidationHandler.

Is this the correct approach ? is there any wait-for-service event I can wait for ?

Code Block
+(void) callXpcWithRetry {
NSXPCConnection* hubConnection = [[NSXPCConnection alloc] initWithMachServiceName:@"com.bla.myservice" options:0];
hubConnection.remoteObjectInterface = getInterface();
[hubConnection setInvalidationHandler:^{
NSLog(@"Connection to keystore hub service invalidated .. retry in 5");
sleep(5);
[ServiceDelegate callXpcWithRetry];
}];
[hubConnection resume];
id<myXpcProtocol> hub = [hubConnection remoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {
}];
[hub xpcProtocolMethodForUser:NSUserName()];
}

Is your XPC service provider by an XPC Service? Or provide by a launchd daemon or agent? Or something else?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
.
My XPC service is a daemon with startup plist file in Library/LaunchDaemons and loaded by launchd upon product installation.

I thought that every XPC service must be managed by launchd, because it's responsible for the routing from client according to mach service name.

I thought that every XPC service must be managed by launchd, because
it's responsible for the routing from client according to mach service
name.

Right. But there are various ways to vend an XPC service, including:
  • launchd daemons

  • launchd agents

  • XPC Services bundled within your app

  • Some more more obscure stuff

My XPC service is a daemon

OK. So presumably both the daemon and your client are being installed at the same time. Do you synchronise that work? Specifically, are you sure that launchctl has returned before your client starts?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Xpc client waiting for service up indication.
 
 
Q