From 4335e1845ddc6939a160c4d3d08e70473e80c75d Mon Sep 17 00:00:00 2001 From: nield Date: Sun, 21 Sep 2025 04:42:26 +0200 Subject: [PATCH] flush-macos-patch: Always flush after write on MacOS On MacOS Apple's limited and deprecated Secure Transport API is used which can cause problems when a complex stream with an internal buffering mechanism is used. We should flush after each write on MacOS to maintain a stable usage. --- tokio-native-tls/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tokio-native-tls/src/lib.rs b/tokio-native-tls/src/lib.rs index 8ce19c0..4636bd8 100644 --- a/tokio-native-tls/src/lib.rs +++ b/tokio-native-tls/src/lib.rs @@ -147,7 +147,14 @@ where S: AsyncWrite + Unpin, { fn write(&mut self, buf: &[u8]) -> io::Result { - self.with_context(|ctx, stream| stream.poll_write(ctx, buf)) + let n = self.with_context(|ctx, stream| stream.poll_write(ctx, buf))?; + + #[cfg(target_os = "macos")] + { + self.flush()?; + } + + Ok(n) } fn flush(&mut self) -> io::Result<()> {