nym icon indicating copy to clipboard operation
nym copied to clipboard

Remove all cancel unsafe calls from `select!`s

Open neacsu opened this issue 3 years ago • 0 comments

From all the select!s in the repository, there are at least 7 occurrences where there is a loop encapsulating the select! and at least two branches which don't break the loop (most of the select!s that catch the shutdown signal also break the loop, so those shouldn't be a problem).

One example:

while !self.shutdown.is_shutdown() {
    tokio::select! {
        action = self.incoming_actions.next() => ....
        expired_ack = self.pending_acks_timers.next() => ....
        ....
    }
}

In this case neither of the two has an unconditional break of the while loop, and both of them are not cancel safe:

  • incoming_actions is a futures::channel::mpsc::UnboundedReceiver, which is not cancel safe and should replaced with its tokio counterpart.
  • pending_acks_timers locally implements Stream, which is not cancel safe either

We should make sure that all the select! branches are either cancel safe, or at least they get cancelled in unrecoverable situations (such as shutdown).

neacsu avatar Sep 23 '22 12:09 neacsu