[net-tokio] Explicitly yield after processing messages from a peer
authorMatt Corallo <git@bluematt.me>
Tue, 22 Mar 2022 21:03:41 +0000 (21:03 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 10 May 2022 23:40:20 +0000 (23:40 +0000)
This reduces instances of disconnect peers after single timer
intervals somewhat, at least on Tokio 1.14.

lightning-net-tokio/src/lib.rs

index fc7b260e41bf1c6d54d8df15436cf865f64629ed..3cfed870b31f59ae1b36ffbf7a1987eee2b0df00 100644 (file)
@@ -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 {