diff --git a/crates/tx5-go-pion/src/data_chan.rs b/crates/tx5-go-pion/src/data_chan.rs index 89ab5b41..2df964b3 100644 --- a/crates/tx5-go-pion/src/data_chan.rs +++ b/crates/tx5-go-pion/src/data_chan.rs @@ -149,10 +149,14 @@ impl DataChannel { { let mut lock = self.0.lock().unwrap(); + let mut do_swap = false; if let Ok(core) = &mut *lock { core.close(err); + do_swap = true; + } + if do_swap { + std::mem::swap(&mut *lock, &mut tmp); } - std::mem::swap(&mut *lock, &mut tmp); } // make sure the above lock is released before this is dropped diff --git a/crates/tx5-go-pion/src/peer_con.rs b/crates/tx5-go-pion/src/peer_con.rs index 8f29e116..1c5edf45 100644 --- a/crates/tx5-go-pion/src/peer_con.rs +++ b/crates/tx5-go-pion/src/peer_con.rs @@ -226,10 +226,14 @@ impl PeerConnection { { let mut lock = self.0.lock().unwrap(); + let mut do_swap = false; if let Ok(core) = &mut *lock { core.close(err.clone()); + do_swap = true; + } + if do_swap { + std::mem::swap(&mut *lock, &mut tmp); } - std::mem::swap(&mut *lock, &mut tmp); } // make sure the above lock is released before this is dropped