Skip to content

Commit

Permalink
peer_connection: Fix state transition race
Browse files Browse the repository at this point in the history
DTLS transport state was previously acquired and sent over to the async
context returned. This would in some rare cases obviously lead to
updating peer connection state with an old DTLS transport state.
This would in turn lead to PeerConnection not updating it's state
correctly. Sometimes we would see PeerConnection never reaching Connected.
  • Loading branch information
haaspors committed Aug 2, 2024
1 parent f599514 commit fcdef6f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion webrtc/src/peer_connection/peer_connection_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,13 +1168,13 @@ impl PeerConnectionInternal {
}
};

let dtls_transport = Arc::clone(&dtls_transport);
let ice_connection_state2 = Arc::clone(&ice_connection_state);
let on_ice_connection_state_change_handler2 =
Arc::clone(&on_ice_connection_state_change_handler);
let on_peer_connection_state_change_handler2 =
Arc::clone(&on_peer_connection_state_change_handler);
let is_closed2 = Arc::clone(&is_closed);
let dtls_transport_state = dtls_transport.state();
let peer_connection_state2 = Arc::clone(&peer_connection_state);
Box::pin(async move {
RTCPeerConnection::do_ice_connection_state_change(
Expand All @@ -1184,6 +1184,7 @@ impl PeerConnectionInternal {
)
.await;

let dtls_transport_state = dtls_transport.state();
RTCPeerConnection::update_connection_state(
&on_peer_connection_state_change_handler2,
&is_closed2,
Expand Down

0 comments on commit fcdef6f

Please sign in to comment.