diff options
author | Himbeer <himbeer@disroot.org> | 2025-03-24 11:45:56 +0100 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2025-03-24 11:45:56 +0100 |
commit | 25469e8f1a5d65f38847316098386e2193b44570 (patch) | |
tree | f878e5563d77ad10dc4bf5027624e9959fce295b | |
parent | 37d506783220198f52a594f010dea642975eee4f (diff) |
Set read/write timeouts on TcpStreams
This prevents indefinite blocking and ensures that timeout conditions
get detected.
-rw-r--r-- | src/main.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index e122e74..b6b98c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -145,6 +145,9 @@ fn handle_conn_check( raddr: SocketAddr, inbound_healthy: &mut bool, ) -> io::Result<()> { + conn.set_read_timeout(Some(TCP_TIMEOUT))?; + conn.set_write_timeout(Some(TCP_TIMEOUT))?; + let mut buf = [0; 4]; loop { match conn.read_exact(&mut buf) { @@ -167,6 +170,9 @@ fn handle_conn_check( } fn handle_conn_monitor(mut conn: TcpStream, raddr: SocketAddr) -> io::Result<()> { + conn.set_read_timeout(Some(TCP_TIMEOUT))?; + conn.set_write_timeout(Some(TCP_TIMEOUT))?; + let mut buf = [0; 4]; loop { match conn.read_exact(&mut buf) { @@ -205,6 +211,8 @@ fn check_connectivity( if let Some(mut conn4) = conn4 { conn4.write_all(b"GET / HTTP/1.1")?; + conn4.set_read_timeout(Some(TCP_TIMEOUT))?; + conn4.set_write_timeout(Some(TCP_TIMEOUT))?; loop { match conn4.read(&mut buf) { @@ -239,6 +247,8 @@ fn check_connectivity( if let Some(mut conn6) = conn6 { conn6.write_all(b"GET / HTTP/1.1")?; + conn6.set_read_timeout(Some(TCP_TIMEOUT))?; + conn6.set_write_timeout(Some(TCP_TIMEOUT))?; loop { match conn6.read(&mut buf) { |