Skip to content

Commit 815604c

Browse files
committed
fix: 本地端口连接失败导致程序退出
1 parent 4670326 commit 815604c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/server/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,18 @@ async fn server(config: &Properties) -> Result<(), Error> {
114114
info!("Proxy to: {}", config.proxy);
115115

116116
while let Ok((stream, peer)) = server.accept().await {
117-
info!("Client connected: {}", peer);
118-
let tcp = TcpStream::connect(&config.proxy).await.unwrap();
119-
tokio::spawn(accept_connection(stream, tcp));
117+
let dest = config.proxy.clone();
118+
tokio::spawn(async move {
119+
info!("Client connected: {}", peer);
120+
let tcp = match TcpStream::connect(dest).await {
121+
Ok(tcp) => tcp,
122+
Err(e) => {
123+
error!("Client rejected: {} cause {}", peer, e);
124+
return;
125+
}
126+
};
127+
accept_connection(stream, tcp).await;
128+
});
120129
}
121130

122131
Ok(())

0 commit comments

Comments
 (0)