Skip to content

Commit

Permalink
fix: udp session reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
Itsusinn committed Nov 4, 2024
1 parent 09dc5df commit 4fb48d5
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions tuic-server/src/connection/udp_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tokio::{
net::UdpSocket,
sync::{RwLock as AsyncRwLock, oneshot},
};
use tracing::{trace, warn};
use tracing::{debug, warn};
use tuic::Address;

use super::Connection;
Expand Down Expand Up @@ -98,7 +98,13 @@ impl UdpSession {
// Avoid client didn't send `UDP-DROP` properly
_ = timeout.tick() => {
session_listening.close().await;
break
warn!(
"[{id:#010x}] [{addr}] [{user}] [packet] [{assoc_id:#06x}] UDP session timeout",
id = session_listening.conn.id(),
addr = session_listening.conn.inner.remote_address(),
user = session_listening.conn.auth,
);
continue;
},
// `UDP-DROP`
_ = &mut rx => break
Expand Down Expand Up @@ -130,10 +136,15 @@ impl UdpSession {
.log_err(),
);
}
session_listening
.conn
.udp_sessions
.write()
.await
.remove(&assoc_id);
};

tokio::spawn(listen);

Ok(Arc::downgrade(&session))
}

Expand Down Expand Up @@ -177,7 +188,7 @@ impl UdpSession {

impl Drop for UdpSession {
fn drop(&mut self) {
trace!(
debug!(
"[{id:#010x}] [{addr}] [{user}] udp session get dropped",
id = self.conn.id(),
addr = self.conn.inner.remote_address(),
Expand Down

0 comments on commit 4fb48d5

Please sign in to comment.