Browse Source

Disallow calls to tokio::spawn outside dedicated extension trait

Prevent accidentally spawning a task that could outlive the actor system
and become a zombie.

Any long-lived task should be tied to its owner by keeping RemoteHandle around.
rollover-test-2
Mariusz Klochowicz 3 years ago
parent
commit
6afe3f8e6c
No known key found for this signature in database GPG Key ID: 470C865699C8D4D
  1. 3
      daemon/clippy.toml
  2. 1
      daemon/src/lib.rs
  3. 4
      daemon/src/tokio_ext.rs

3
daemon/clippy.toml

@ -0,0 +1,3 @@
disallowed-methods = [
"tokio::spawn", # tasks can outlive the actor system, prefer spawn_with_handle()
]

1
daemon/src/lib.rs

@ -1,6 +1,5 @@
#![cfg_attr(not(test), warn(clippy::unwrap_used))]
#![warn(clippy::disallowed_method)]
use crate::db::load_all_cfds;
use crate::maker_cfd::{FromTaker, NewTakerOnline};
use crate::model::cfd::{Cfd, Order, UpdateCfdProposals};

4
daemon/src/tokio_ext.rs

@ -10,6 +10,8 @@ where
F: Future<Output = Result<(), E>> + Send + 'static,
E: fmt::Display,
{
// we want to disallow calls to tokio::spawn outside FutureExt
#[allow(clippy::disallowed_method)]
tokio::spawn(async move {
if let Err(e) = future.await {
tracing::warn!("Task failed: {:#}", e);
@ -40,6 +42,8 @@ where
Self: Future<Output = ()> + Send + 'static,
{
let (future, handle) = self.remote_handle();
// we want to disallow calls to tokio::spawn outside FutureExt
#[allow(clippy::disallowed_method)]
tokio::spawn(future);
handle
}

Loading…
Cancel
Save