diff --git a/easytier-core/src/peers/conn/peer_conn.rs b/easytier-core/src/peers/conn/peer_conn.rs index bac79a43..d58697c0 100644 --- a/easytier-core/src/peers/conn/peer_conn.rs +++ b/easytier-core/src/peers/conn/peer_conn.rs @@ -1476,7 +1476,13 @@ impl PeerConn { let result = if is_heartbeat(&msg) { self.sink.send(msg).await } else { - self.sink.try_send(msg) + let result = self.sink.try_send(msg); + if result.is_ok() && self.sink.ordinary_queue_is_full() { + // Let the writer run before a ready producer fills the next + // turn with drops. Do not wait for capacity or retry the item. + tokio::task::yield_now().await; + } + result }; if let Err(error) = result { if !matches!(error, TunnelError::BufferFull) { @@ -1655,13 +1661,10 @@ mod tests { packet.fill_peer_manager_hdr(1, 2, kind as u8); packet }; - // Do not yield to the writer: exercise the real connection's - // admission policy with its ordinary queue deterministically full. + // Pre-fill without yielding to the writer, then exercise the + // connection's admission policy with its ordinary queue full. for _ in 0..32 { - conn.send_msg(packet(PacketType::Data)) - .now_or_never() - .unwrap() - .unwrap(); + conn.sink.try_send(packet(PacketType::Data)).unwrap(); } let session = Arc::new(PeerSession::new( 2, diff --git a/easytier-core/src/tunnel/mpsc.rs b/easytier-core/src/tunnel/mpsc.rs index c5148400..f8201649 100644 --- a/easytier-core/src/tunnel/mpsc.rs +++ b/easytier-core/src/tunnel/mpsc.rs @@ -52,6 +52,10 @@ impl MpscTunnelSender { TrySendError::Closed(_) => TunnelError::Shutdown, }) } + + pub(crate) fn ordinary_queue_is_full(&self) -> bool { + self.sender.capacity() == 0 + } } /// Only connection writers expand batches. Internal RPC rings keep one entry