From: Matt Corallo Date: Wed, 21 Apr 2021 21:50:41 +0000 (+0000) Subject: [peer_handler] Take the peers lock before getting messages to send X-Git-Tag: v0.0.14~19^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=bfd11282131bd642d7920bf7ad9d1e59d329ccf8;p=rust-lightning [peer_handler] Take the peers lock before getting messages to send Previously, if a user simultaneously called `PeerHandler::process_events()` from two threads, we'd race, which ended up sending messages out-of-order in the real world. Specifically, we first called `get_and_clear_pending_msg_events`, then take the `peers` lock and push the messages we got into the sending queue. Two threads may both get some set of messages to send, but then race each other into the `peers` lock and send the messages in random order. Because we already hold the `peers` lock when calling most message handler functions, we can simply take the lock before calling `get_and_clear_pending_msg_events`, solving the race. --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 9488a34db..d4eb9eae5 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -1020,9 +1020,9 @@ impl PeerManager