From ac87c8df2780cb12c74942ec8a473718c76cb5b7 Mon Sep 17 00:00:00 2001 From: Tommi Date: Thu, 16 Mar 2023 22:17:38 +0100 Subject: [PATCH] Temporary fix to guard against sctp_data_channels_ being modified. Following https://webrtc-review.googlesource.com/c/src/+/297100 it seems that sctp_data_channels_ gets modified while we're iterating through it. This temporary fix creates a copy of the array and iterates through the copy instead of sctp_data_channels_. A follow-up CL (or CLs) will provide more clarity, testing and regression guards. Bug: webrtc:15004 Change-Id: I0cb5dfb6829d36b51328875c8c9cfa392ff393a7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/297981 Commit-Queue: Tomas Gunnarsson Reviewed-by: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#39584} --- pc/data_channel_controller.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pc/data_channel_controller.cc b/pc/data_channel_controller.cc index ca50c346ff..5ff3b1cc4d 100644 --- a/pc/data_channel_controller.cc +++ b/pc/data_channel_controller.cc @@ -100,7 +100,8 @@ void DataChannelController::OnDataReceived( RTC_DCHECK_RUN_ON(signaling_thread()); // TODO(bugs.webrtc.org/11547): The data being received should be // delivered on the network thread. - for (const auto& channel : sctp_data_channels_) { + auto copy = sctp_data_channels_; + for (const auto& channel : copy) { if (channel->id() == channel_id) channel->OnDataReceived(type, buffer); } @@ -113,7 +114,8 @@ void DataChannelController::OnChannelClosing(int channel_id) { SafeTask(signaling_safety_.flag(), [this, channel_id] { RTC_DCHECK_RUN_ON(signaling_thread()); // TODO(bugs.webrtc.org/11547): Should run on the network thread. - for (const auto& channel : sctp_data_channels_) { + auto copy = sctp_data_channels_; + for (const auto& channel : copy) { if (channel->id() == channel_id) channel->OnClosingProcedureStartedRemotely(); } @@ -147,7 +149,8 @@ void DataChannelController::OnReadyToSend() { signaling_thread()->PostTask(SafeTask(signaling_safety_.flag(), [this] { RTC_DCHECK_RUN_ON(signaling_thread()); data_channel_transport_ready_to_send_ = true; - for (const auto& channel : sctp_data_channels_) + auto copy = sctp_data_channels_; + for (const auto& channel : copy) channel->OnTransportReady(true); })); } @@ -408,7 +411,8 @@ void DataChannelController::NotifyDataChannelsOfTransportCreated() { RTC_DCHECK_RUN_ON(network_thread()); signaling_thread()->PostTask(SafeTask(signaling_safety_.flag(), [this] { RTC_DCHECK_RUN_ON(signaling_thread()); - for (const auto& channel : sctp_data_channels_) { + auto copy = sctp_data_channels_; + for (const auto& channel : copy) { channel->OnTransportChannelCreated(); } }));