Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XPC interruption handling #10

Open
MichalMMac opened this issue Mar 13, 2021 · 1 comment
Open

XPC interruption handling #10

MichalMMac opened this issue Mar 13, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@MichalMMac
Copy link
Owner

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:

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

Possible improvements requiring reimplementation:

  • iasagent (iasd too?) should be able to react to signals from launchd (Probably using DispatchSource.makeSignalSource).
  • iasd could implement XPC interruptionHandler and/or invalidationHandler. This would require to make iasd XPC implementation more asynchronous. Also there must be conditions for agent reconnection. Only agent running under the same uid as the previously connected agent would be allowed to check in and resume the work.
  • iasd could save state of the current run (Probably using the NSUserDefaults). It could keep track of task it already executed and those remaining. It could resume the execution where it left off.

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

@MichalMMac MichalMMac added the enhancement New feature or request label Mar 13, 2021
@MichalMMac MichalMMac self-assigned this Mar 13, 2021
@MichalMMac MichalMMac changed the title agent XPC interruption handling XPC interruption handling Mar 13, 2021
@MichalMMac MichalMMac pinned this issue Mar 13, 2021
@MichalMMac
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant