@@ -39,10 +39,19 @@ impl UdpProxy {
3939 buf. set_len ( self . buffer_size ) ;
4040 }
4141 loop {
42- let ( len, addr) = server. recv_from ( & mut buf) . await ?;
42+ let ( len, addr) = match server. recv_from ( & mut buf) . await {
43+ Ok ( res) => res,
44+ Err ( e) => {
45+ eprintln ! ( "[warning][udp][{self}] Failed to recv from downstream: {e}" ) ;
46+ continue ;
47+ }
48+ } ;
4349 match map. read ( ) . await . get ( & addr) {
4450 Some ( tx) => {
45- tx. send ( buf[ ..len] . to_vec ( ) ) . await . unwrap ( ) ;
51+ if let Err ( e) = tx. send ( buf[ ..len] . to_vec ( ) ) . await {
52+ eprintln ! ( "[warning][udp][{self}] Tokio channel error: {e}" ) ;
53+ continue ;
54+ }
4655 }
4756 None => {
4857 let ( tx, mut rx) = mpsc:: channel ( 1 ) ;
@@ -74,18 +83,31 @@ impl UdpProxy {
7483 select ! {
7584 Some ( received) = rx. recv( ) => {
7685 let client_clone = client. clone( ) ;
86+ let self_clone = self_clone. clone( ) ;
7787 tokio:: spawn( async move {
78- client_clone. send( & received) . await . unwrap( ) ;
88+ if let Err ( e) = client_clone. send( & received) . await {
89+ eprintln!(
90+ "[warning][udp][{self_clone}] Failed to send to upstream: {e}"
91+ ) ;
92+ }
7993 } ) ;
8094 }
8195 Ok ( len) = client. recv( & mut buf) => {
96+ let self_clone = self_clone. clone( ) ;
8297 let server_clone = server_clone. clone( ) ;
8398 let data = buf[ ..len] . to_vec( ) ;
8499 tokio:: spawn( async move {
85- server_clone. send_to( & data, & addr) . await . unwrap( ) ;
100+ if let Err ( e) = server_clone. send_to( & data, & addr) . await {
101+ eprintln!(
102+ "[warning][udp][{self_clone}] Failed to send to downstream: {e}"
103+ ) ;
104+ }
86105 } ) ;
87106 }
88107 _ = tokio:: time:: sleep( Duration :: from_secs( 60 ) ) => {
108+ println!(
109+ "[info][udp][{self_clone}] No data transport for 60 seconds, closing connection"
110+ ) ;
89111 break ;
90112 }
91113 }
0 commit comments