diff --git a/src/conn.rs b/src/conn.rs index f8f8149..564b7e7 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -249,6 +249,7 @@ impl Connection { tokio::pin!(idle_timeout); loop { tokio::select! { + biased; Some(event) = stream_events.recv() => { match event { StreamEvent::Incoming(packet) => { @@ -263,12 +264,6 @@ impl Connection { } } } - Some(Ok(timeout)) = self.unacked.next() => { - let (seq, packet) = timeout; - tracing::debug!(seq, ack = %packet.ack_num(), packet = ?packet.packet_type(), "timeout"); - - self.on_timeout(packet, Instant::now()); - } Some(write) = writes.recv(), if !shutting_down => { // Reset the idle timeout on any new write. let idle_deadline = tokio::time::Instant::now() + self.config.max_idle_timeout; @@ -285,6 +280,12 @@ impl Connection { _ = self.writable.notified() => { self.process_writes(Instant::now()); } + Some(Ok(timeout)) = self.unacked.next() => { + let (seq, packet) = timeout; + tracing::debug!(seq, ack = %packet.ack_num(), packet = ?packet.packet_type(), "timeout"); + + self.on_timeout(packet, Instant::now()); + } () = &mut idle_timeout => { if !std::matches!(self.state, State::Closed { .. }) { let unacked: Vec = self.unacked.keys().copied().collect();