Files
firezone/rust/windows-client/docs
Reactor Scram 2ee6eb5d88 fix(windows): Ensure crashes, errors, and panics are all logged to file (#3572)
Closes #3567 

This doesn't feel complete, but there isn't much more I can do without
changing lots of code and doing more research, and I don't want to hold
up the Windows beta for error handling that may not be used.

I'm only handling crashes, errors, and panics in the `Controller` task
since it's hard to simulate them elsewhere. Everything else like the
wintun worker thread will have to be best-effort or tested by modifying
the code temporarily.

Crashes go to stderr and and the log file, and we can get a line number
from the crash dump:

![image](https://github.com/firezone/firezone/assets/13400041/bbabcdb5-9d59-40b8-9b2f-bff2c88d8a88)

Errors go to stderr and the log file, but we don't get a line number,
because we aren't capturing the backtrace:

![image](https://github.com/firezone/firezone/assets/13400041/31e13b5a-aec7-4b3c-91e0-d0f230f4dfd3)

Panics go to stderr and the log file, but we don't even get the panic
message. I don't think I can do much about that. Tokio doesn't give us
the full `PanicInfo`, which contains the message and location (line
number). If we end up debugging a panic in prod we could bisect by
putting tighter bounds until we narrow it down.

![image](https://github.com/firezone/firezone/assets/13400041/20337dde-911a-4edf-8d68-829ed9aebc27)

The panic hook ends up not triggered because:
- If I don't catch the panic, the app won't close, because Tokio will
catch the panic
- If I do catch the panic, I can't call the panic hook manually, because
Tokio doesn't give me a `PanicInfo` struct. And I can't resume the
panic, because I'm still inside a Tokio task.

I don't think there's any point capturing a crash dump on panic, because
Tokio will have already stopped the panicked thread, and the backtrace
will only show the catch location.

Maybe the message would print if I changed the controller task to a
controller thread, so that panicking that thread will trigger
`tracing_panic` and then abort the process? But that's a bigger change.

---------

Signed-off-by: Reactor Scram <ReactorScram@users.noreply.github.com>
Co-authored-by: Gabi <gabrielalejandro7@gmail.com>
2024-02-06 20:30:05 +00:00
..