From 0a9ce77be8de7cc2d13e6eecd9442c4f74d107ef Mon Sep 17 00:00:00 2001 From: Eric Rodrigues Pires Date: Thu, 3 Jul 2025 22:34:11 -0300 Subject: [PATCH] Move TCP connections to spawned tasks and fix logs --- CHANGELOG.md | 5 +++++ src/tcp.rs | 39 ++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7773238..a486106 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ - Use tracing for HTTP logs. +### Fixed + +- Move TCP connections to spawned tasks. +- Fix TCP logs. + ## 0.6.0 (2025-06-29) ### Changed diff --git a/src/tcp.rs b/src/tcp.rs index b447876..cdca896 100644 --- a/src/tcp.rs +++ b/src/tcp.rs @@ -74,7 +74,7 @@ impl PortHandler for Arc { if !clone.disable_tcp_logs { let _ = handler.log_channel().send( format!( - "New connection from {}:{} to TCP port {}", + "New connection from {}:{} to TCP port {}\r\n", address.ip().to_canonical(), address.port(), port @@ -83,27 +83,32 @@ impl PortHandler for Arc { ); } // Copy data between the TCP stream and the reverse forwarding channel, with optional timeout + let buffer_size = clone.buffer_size; match clone.tcp_connection_timeout { Some(duration) => { - let _ = timeout(duration, async { - copy_bidirectional_with_sizes( + tokio::spawn(async move { + let _ = timeout(duration, async { + copy_bidirectional_with_sizes( + &mut stream, + &mut channel, + buffer_size, + buffer_size, + ) + .await + }) + .await; + }); + } + None => { + tokio::spawn(async move { + let _ = copy_bidirectional_with_sizes( &mut stream, &mut channel, - clone.buffer_size, - clone.buffer_size, + buffer_size, + buffer_size, ) - .await - }) - .await; - } - None => { - let _ = copy_bidirectional_with_sizes( - &mut stream, - &mut channel, - clone.buffer_size, - clone.buffer_size, - ) - .await; + .await; + }); } } } -- 2.51.2