MichalMMac / installapplications-swiftly

Swift successor to InstallApplications
MIT License
9 stars 1 forks source link

XPC interruption handling #10

Open MichalMMac opened 3 years ago

MichalMMac commented 3 years ago

Current XPC implementation is very synchronous. There is an assumption iasagent is going to do all required work after successfull check in.

If iasagent is terminated for any reason before it finishes its work all remaining user scripts won't be executed (iasd considers them failed with exit code 1). User initiated log out might be the prime case of this situation.

There should be more testing into edge cases:

Possible improvements requiring reimplementation:

On the other hand making IAS more stateful and async friendly will result in more complexity. Is the complexity worth the gain?

MichalMMac commented 3 years ago

What happens if iasagent is terminated when it is waiting for userscript to finish?

synchronousRemoteObjectProxyWithErrorHandler error handler is called. Currently it only logs error to the system log. This is satisfactory behaviour in synchronous scenario so there is little need to look at interruptionHandler or invalidationHandler which would useful mainly in async approach to XPC.

It should be possible to throw an exception within the runUserScript() method. Caller could then start waiting for agent to reconnect via agentCheckIn. However using DispatchSemaphore in current form won't work if multiple parallel threads are waiting for agent to reconnect. We would need synchronisation mechanism where a single signal (new agent connection) would unblock N waiting threads.

Question remains if it makes sense to add complex logic to current synchronous XPC code or attempt to rework it into async.