bitcoin-dev-project/sim-ln

Robustness: Use Listen and Shutdown Trigger Universally

Closed this issue · 0 comments

Right now, we rely on some of the mechanics of mpsc channels to handle shutdown in places. We should move the code base over to using trigger to handle shutdown everywhere to improve readability.

1. Listen for shutdown in channel send/recieve

select! on listener for every channel Send and Receive, exiting if we get the signal to shut down

Eg: rather than send, select on listener to abort send if we need to exit:

select! {
    biased;
    _ = listener.clone() => {
        // log something here
        break;
    },
    send_res = sender.send(outcome) => {
        match send_res {
            Ok(_) => {},
            Err(e) => {
                log::error!("Error sending action outcome: {:?}.", e);
                break;
            }
        }
    },
}

2. Always trigger shutdown on error

Call trigger to signal shutdown if any task exits with an error - eg results consumer and event consumer. Run through codebase to cover all of these cases.

3. Doc Update

The shutdown section of the docs should be updated to reflect the simplified handling as part of this issue.