mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-11-28 08:00:19 +00:00
fix(peers): yield to connection writers after filling the queue
A ready packet source can enqueue more than 32 packets without yielding. After ordinary sends switched to try_send, the writer can lose its turn until the remainder of a burst has been dropped. This loses fragments of a maximum-size UDP datagram and stalls data-plane TCP teardown. Yield once after a successful ordinary enqueue consumes the last slot. Already-full queues still return BufferFull immediately. There is no capacity wait, retry or queue-size change; heartbeat admission and fatal connection errors keep their existing behavior. Pre-fill the overflow fixture through the sink so it retains a blocked writer while checking actual PeerConn admission and closure semantics. The original failing gateway tests remain unchanged. Validation: - Reproduce both CI failures and confirm BufferFull events during each. - Pass both original tests and 31 relevant data-plane, queue, heartbeat, writer-cleanup and Portal lifecycle regressions. - Pass cargo fmt --all -- --check and strict workspace all-target clippy with full features. - Complete independent read-only review of the frozen diff: no findings.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user