Skip to content

Commit

Permalink
avoid reconnection logs on normal close (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom authored Sep 30, 2024
1 parent dd5cb7e commit 5bc686b
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions livekit/src/rtc_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ struct EngineHandle {
session: Arc<RtcSession>,
closed: bool,
reconnecting: bool,
can_reconnect: bool,

// If full_reconnect is true, the next attempt will not try to resume
// and will instead do a full reconnect
Expand Down Expand Up @@ -318,6 +319,7 @@ impl EngineInner {
session: Arc::new(session),
closed: false,
reconnecting: false,
can_reconnect: true,
full_reconnect: false,
engine_task: None,
}),
Expand Down Expand Up @@ -402,15 +404,25 @@ impl EngineInner {
async fn on_session_event(self: &Arc<Self>, event: SessionEvent) -> EngineResult<()> {
match event {
SessionEvent::Close { source, reason, action, retry_now } => {
log::warn!("received session close: {:?} {:?} {:?}", source, reason, action);
match action {
proto::leave_request::Action::Resume => {
self.reconnection_needed(retry_now, false)
}
proto::leave_request::Action::Reconnect => {
self.reconnection_needed(retry_now, true)
proto::leave_request::Action::Resume
| proto::leave_request::Action::Reconnect => {
log::warn!(
"received session close: {:?} {:?} {:?}",
source,
reason,
action
);
self.reconnection_needed(
retry_now,
action == proto::leave_request::Action::Reconnect,
);
}
proto::leave_request::Action::Disconnect => {
// Disallow reconnection to avoid races
let mut running_handle = self.running_handle.write();
running_handle.can_reconnect = false;

// Spawning a new task because the close function wait for the engine_task to
// finish. (So it doesn't make sense to await it here)
livekit_runtime::spawn({
Expand Down Expand Up @@ -505,6 +517,11 @@ impl EngineInner {
/// Ask for a full reconnect if `full_reconnect` is true
fn reconnection_needed(self: &Arc<Self>, retry_now: bool, full_reconnect: bool) {
let mut running_handle = self.running_handle.write();

if !running_handle.can_reconnect {
return;
}

if running_handle.reconnecting {
// If we're already reconnecting just update the interval to restart a new attempt
// ASAP
Expand Down

0 comments on commit 5bc686b

Please sign in to comment.