SecureXPC icon indicating copy to clipboard operation
SecureXPC copied to clipboard

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

Open rurza opened this issue 2 years ago • 5 comments

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

rurza avatar Apr 25 '23 22:04 rurza

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.

rurza avatar Apr 26 '23 09:04 rurza

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

jakaplan avatar Apr 26 '23 10:04 jakaplan

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 avatar Apr 30 '23 11:04 jakaplan

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?

jakaplan avatar May 10 '23 08:05 jakaplan

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

rurza avatar May 13 '23 20:05 rurza