From 11955f6849a6b608639c13aed8cf07ad9903d437 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Tue, 17 Mar 2026 18:14:59 +0800 Subject: [PATCH] Fix read refcount for ChanIn and ChanInOut clone() The read refcount wasn't incremented on ChanIn or ChanInOut clone. This could result in input being discarded if the read refcount hit zero. It isn't clear whether this could result in missed EOF (which has been reported). --- async/src/async_channel.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/async/src/async_channel.rs b/async/src/async_channel.rs index 6306d599..4db80865 100644 --- a/async/src/async_channel.rs +++ b/async/src/async_channel.rs @@ -113,7 +113,7 @@ impl Write for ChanIO<'_> { /// Otherwise ordering will be arbitrary, and if competing readers or writers /// are in different tasks, there will be churn as they continually wake /// each other up. Simultaneous single-reader and single-writer is fine. -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct ChanIn<'g>(ChanIO<'g>); impl<'g> ChanIn<'g> { @@ -134,6 +134,12 @@ impl Drop for ChanIn<'_> { } } +impl Clone for ChanIn<'_> { + fn clone(&self) -> Self { + Self::new(self.0.clone()) + } +} + /// An output-only SSH channel. /// /// This is used as stderr for a server, or can also be obtained using @@ -187,7 +193,7 @@ impl<'g> ChanOut<'g> { /// Otherwise ordering will be arbitrary, and if competing readers or writers /// are in different tasks, there will be churn as they continually wake /// each other up. Simultaneous single-reader and single-writer is fine. -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct ChanInOut<'g>(ChanIO<'g>); impl<'g> ChanInOut<'g> { @@ -225,6 +231,12 @@ impl Drop for ChanInOut<'_> { } } +impl Clone for ChanInOut<'_> { + fn clone(&self) -> Self { + Self::new(self.0.clone()) + } +} + impl ErrorType for ChanInOut<'_> { type Error = sunset::Error; }