Dont drop half of the TCP stream before dropping the whole thing

This commit is contained in:
Mike Dilger 2024-07-31 07:48:13 +12:00
parent d8689540d8
commit 4d300eb12a

View File

@ -8,7 +8,6 @@ use std::fs::OpenOptions;
use std::io::Read; use std::io::Read;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use std::time::Duration; use std::time::Duration;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpListener; use tokio::net::TcpListener;
use tokio::signal::unix::{signal, SignalKind}; use tokio::signal::unix::{signal, SignalKind};
@ -87,7 +86,7 @@ async fn main() -> Result<(), Error> {
// Accepts network connections and spawn a task to serve each one // Accepts network connections and spawn a task to serve each one
v = listener.accept() => { v = listener.accept() => {
let (mut tcp_stream, hashed_peer) = { let (tcp_stream, hashed_peer) = {
let (tcp_stream, peer_addr) = v?; let (tcp_stream, peer_addr) = v?;
let hashed_peer = HashedPeer::new(peer_addr); let hashed_peer = HashedPeer::new(peer_addr);
(tcp_stream, hashed_peer) (tcp_stream, hashed_peer)
@ -103,7 +102,8 @@ async fn main() -> Result<(), Error> {
"{}: Blocking reconnection until {}", "{}: Blocking reconnection until {}",
hashed_peer.ip(), hashed_peer.ip(),
ip_data.ban_until); ip_data.ban_until);
let _ = tcp_stream.shutdown().await; // note: no need to shutdown() which only drops the write half.
// the whole thing gets dropped when we continue.
continue; continue;
} }
} }