Skip to content

Commit 3d0bb59

Browse files
committed
[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.
1 parent 81a4bd1 commit 3d0bb59

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ impl Connection {
194194
},
195195
}
196196
let _ = event_waker.try_send(());
197+
198+
// At this point we've processed a message or two, and reset the ping timer for this
199+
// peer, at least in the "are we still receiving messages" context, if we don't give up
200+
// our timeslice to another task we may just spin on this peer, starving other peers
201+
// and eventually disconnecting them for ping timeouts. Instead, we explicitly yield
202+
// here.
203+
tokio::task::yield_now().await;
197204
};
198205
let writer_option = us.lock().unwrap().writer.take();
199206
if let Some(mut writer) = writer_option {

0 commit comments

Comments
 (0)