trilemma-dev / SecureXPC

A simple and secure XPC framework for Swift
MIT License
73 stars 15 forks source link

setErrorHandler won't be called when using on server with startAndBlock #130

Open rurza opened 1 year ago

rurza commented 1 year ago

It seems that XPCServer's setErrorHandler won't be called, until the connection is closed. I believe it's a bug.

rurza commented 1 year ago

After some digging it seems that errors I was seeing were mapped to the client errors.

Screenshot 2023-04-26 at 11 40 16

What we're seeing here: BatFi, the app has a timer that sends messages and fails. Then I killed the application, and helper's errorHandler was called.

jakaplan commented 1 year ago

Thanks for the bug report. I will take a look this weekend.

jakaplan commented 1 year ago

Could you provide the actual code or some description of the code involved that's causing this behavior?

Does BatFi contain usage of XPCClient and BatFiHelper have an XPCServer? That's what I'd assume based on typical helper patterns using XPC, but it's surprising to see connectionInvalid as a server side error - it ought to only be possible on the client side.

jakaplan commented 1 year ago

Now that I have access to the source code I tried to replicate this issue, but I'm not sure how to.

I modified RouteHandler.smcStatus(...) to always throw an error and then called the corresponding route from the client and everything worked as expected. However, that's an error generated by the application code whereas what you show in the screenshot is a framework error which I wouldn't expect to occur (because as previously mentioned connectionInvalid ought to only be a client side error).

Could you provide me repro steps and/or a branch of your repository that will automatically replicate this issue upon first run?

rurza commented 1 year ago

Hey! Check out this branch: https://github.com/rurza/BatFi/tree/SecureXPC-errorHandler

1) Run the app, and install the helper tool. Run commands "turn off charging" and "turn on charging" commands X times. You should get the SecureXPC.XPCError.insecure error. Great :) Now you can open the Console.app, start streaming messages. You can filter them by software.micropixels.BatFi.Helper. Quit the app. 2) Jackpot, the helper error handler will be called X times