From: Matt Corallo Date: Tue, 22 Mar 2022 21:03:41 +0000 (+0000) Subject: [net-tokio] Explicitly yield after processing messages from a peer X-Git-Tag: v0.0.107~31^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=b222be233b0267ac2012a09e0d1c8ffee9cd2982;p=rust-lightning [net-tokio] Explicitly yield after processing messages from a peer This reduces instances of disconnect peers after single timer intervals somewhat, at least on Tokio 1.14. --- diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index fc7b260e4..3cfed870b 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -194,6 +194,13 @@ impl Connection { }, } let _ = event_waker.try_send(()); + + // At this point we've processed a message or two, and reset the ping timer for this + // peer, at least in the "are we still receiving messages" context, if we don't give up + // our timeslice to another task we may just spin on this peer, starving other peers + // and eventually disconnecting them for ping timeouts. Instead, we explicitly yield + // here. + tokio::task::yield_now().await; }; let writer_option = us.lock().unwrap().writer.take(); if let Some(mut writer) = writer_option {