rust-teos icon indicating copy to clipboard operation
rust-teos copied to clipboard

Consider setting panic to abort in teos

Open sr-gi opened this issue 3 years ago • 4 comments

The panic behavior is set to unwind at the moment (default), however, this means that if an async task fails, the daemon may not crash but the task will. This can set the daemon in a weird state where some things are expected to be running but they are not.

An example to this is trying to run the daemon with tor support while the tor connection cannot be stablished:

> ./target/debug/teosd --torsupport
Loading configuration from file
2022-05-16T20:28:27.679Z INFO [teosd] tower_id: 02bd2b759dd8a4fcef0f7d9692c105da8400d5da7942ee039e869fbfb8738ffde4
2022-05-16T20:28:27.683Z INFO [teosd] Last known block: 489b5e533c960d070795bb49cdc9d8dad15aef3414d77449107a84beaeb41020
2022-05-16T20:28:27.690Z INFO [teosd] Bootstrapping from backed up data
2022-05-16T20:28:27.690Z INFO [teosd] Bootstrap completed. Turning on interfaces
2022-05-16T20:28:27.690Z INFO [teosd] Starting up hidden tor service
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: ConnectionRefused, error: Custom { kind: ConnectionRefused, error: "failed to connect to tor control port" } }', teos/src/main.rs:281:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2022-05-16T20:29:11.532Z INFO [teos::api::http] Received get_appointment request from 127.0.0.1:53555
2022-05-16T20:29:11.553Z INFO [teos::api::http] Request failed, error_code=7
2022-05-16T20:29:11.985Z INFO [teos::api::http] Received get_appointment request from 127.0.0.1:53556
2022-05-16T20:29:12.004Z INFO [teos::api::http] Request failed, error_code=7

We should consider changing the panic behavior or making this crash the daemon in some way.

Source: https://users.rust-lang.org/t/panic-in-tokio-task-does-not-end-the-program-execution/45731

sr-gi avatar May 18 '22 08:05 sr-gi

@tee8z

sr-gi avatar May 18 '22 08:05 sr-gi

In the Cargo.toml file we can configure the program to abort on panic instead by adding:

[profile.release]
panic = 'abort'

I'm not familiar with the entire codebase so I'm not sure if this will cause any other issues, though if it does we probably want to handle those panics differently as well.

Thoughts? I'd be happy to open a PR to fix this.

booklearner avatar Jul 28 '22 01:07 booklearner

@booklearner I'm pretty sure I tried that back in the day but it didn't work. You're more than welcome to give it a go though.

sr-gi avatar Jul 28 '22 09:07 sr-gi

Keeping an eye on this https://github.com/tokio-rs/tokio/issues/4516

sr-gi avatar Aug 24 '22 12:08 sr-gi