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 <tommi@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39584}
This commit is contained in:
Tommi 2023-03-16 22:17:38 +01:00 committed by WebRTC LUCI CQ
parent c4edef7c73
commit ac87c8df27

View File

@ -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();
}
}));