lighthouse/common
Michael Sproul 58012f85e1 Shutdown gracefully on panic (#2596)
## Proposed Changes

* Modify the `TaskExecutor` so that it spawns a "monitor" future for each future spawned by `spawn` or `spawn_blocking`. This monitor future joins the handle of the child future and shuts down the executor if it detects a panic.
* Enable backtraces by default by setting the environment variable `RUST_BACKTRACE`.
* Spawn the `ProductionBeaconNode` on the `TaskExecutor` so that if a panic occurs during start-up it will take down the whole process. Previously we were using a raw Tokio `spawn`, but I can't see any reason not to use the executor (perhaps someone else can).

## Additional Info

I considered using [`std::panic::set_hook`](https://doc.rust-lang.org/std/panic/fn.set_hook.html) to instantiate a custom panic handler, however this doesn't allow us to send a shutdown signal because `Fn` functions can't move variables (i.e. the shutdown sender) out of their environment. This also prevents it from receiving a `Logger`.  Hence I decided to leave the panic handler untouched, but with backtraces turned on by default.

I did a run through the code base with all the raw Tokio spawn functions disallowed by Clippy, and found only two instances where we bypass the `TaskExecutor`: the HTTP API and `InitializedValidators` in the VC. In both places we use `spawn_blocking` and handle the return value, so I figured that was OK for now.

In terms of performance I think the overhead should be minimal. The monitor tasks will just get parked by the executor until their child resolves.

I've checked that this covers Discv5, as the `TaskExecutor` gets injected into Discv5 here: f9bba92db3/beacon_node/src/lib.rs (L125-L126)
2021-09-15 00:01:18 +00:00
..
account_utils Upgrade dependencies (#2513) 2021-08-17 01:00:24 +00:00
clap_utils Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
compare_fields Check for unused deps in CI (#1262) 2020-06-14 10:59:50 +10:00
compare_fields_derive Update external deps (#1711) 2020-10-05 08:22:19 +00:00
deposit_contract Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
directory fix default network handling (#2029) 2020-12-08 05:41:10 +00:00
eth2 Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
eth2_config Improve ergonomics of adding a new network config (#2489) 2021-08-30 23:27:28 +00:00
eth2_interop_keypairs Fix nightly bump num bigint (#2591) 2021-09-12 23:55:20 +00:00
eth2_network_config Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
eth2_wallet_manager Rust 1.54.0 lints (#2483) 2021-07-30 01:11:47 +00:00
fallback Improve eth1 fallback logging (#2490) 2021-08-30 00:51:26 +00:00
filesystem Update file permissions (#2499) 2021-09-03 02:41:10 +00:00
hashset_delay Upgrade dependencies (#2513) 2021-08-17 01:00:24 +00:00
lighthouse_metrics [Altair] Sync committee pools (#2321) 2021-07-15 00:52:02 +00:00
lighthouse_version v1.5.2 (#2595) 2021-09-13 23:01:19 +00:00
lockfile Enable Compatibility with Windows (#2333) 2021-05-19 23:05:16 +00:00
logging Rust 1.54.0 lints (#2483) 2021-07-30 01:11:47 +00:00
lru_cache Keep track of failed head chains and prevent re-lookups (#1534) 2020-08-18 03:54:09 +00:00
malloc_utils Modify Malloc Tuning (#2398) 2021-06-09 02:30:06 +00:00
monitoring_api Upgrade dependencies (#2513) 2021-08-17 01:00:24 +00:00
sensitive_url Add SensitiveUrl to redact user secrets from endpoints (#2326) 2021-05-04 01:59:51 +00:00
slot_clock Validator monitor support for sync committees (#2476) 2021-08-31 23:31:36 +00:00
target_check Improve compilation error on 32-bit (#2424) 2021-06-30 04:56:22 +00:00
task_executor Shutdown gracefully on panic (#2596) 2021-09-15 00:01:18 +00:00
test_random_derive Update external deps (#1711) 2020-10-05 08:22:19 +00:00
validator_dir Updates to make crates publishable (#2472) 2021-09-03 01:10:25 +00:00
warp_utils Upgrade dependencies (#2513) 2021-08-17 01:00:24 +00:00
README.md Directory Restructure (#1163) 2020-05-18 21:24:23 +10:00

eth2

Common crates containing eth2-specific logic.