Don't report ECONNABORT or ECONNRESET as read errors

If we're just idle waiting for bytes to become available to read and the
connection is forcibly reset or aborted, just treat it as if it were closed
normally. This lets us bubble back the actual number of bytes transmitted.

We are still treating these as errors if we encounter them while actively trying
to write to the host/client.

Should resolve https://github.com/mqudsi/tcpproxy/issues/3
This commit is contained in:
Mahmoud Al-Qudsi 2023-08-28 17:38:59 -05:00
parent ae56848993
commit ca67fd31ca
1 changed files with 6 additions and 1 deletions

View File

@ -106,7 +106,12 @@ async fn forward(bind_ip: &str, local_port: i32, remote: &str) -> Result<(), Box
biased;
result = read.read(&mut buf) => {
bytes_read = result?;
use std::io::ErrorKind::{ConnectionReset, ConnectionAborted};
bytes_read = result.or_else(|e| match e.kind() {
// Consider these to be part of the proxy life, not errors
ConnectionReset | ConnectionAborted => Ok(0),
_ => Err(e)
})?;
},
_ = abort.recv() => {
break;