aboutsummaryrefslogtreecommitdiff
path: root/media/sctp
diff options
context:
space:
mode:
authorFlorent Castelli <orphis@webrtc.org>2022-02-21 14:39:47 +0100
committerWebRTC LUCI CQ <webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-02-22 10:21:26 +0000
commit9bbfe9e5e09e12ea78048c610de85aeb5970176e (patch)
treecdd5a3eb419b3135641e6920454b820edc2835ab /media/sctp
parent7b0a30ec9ac7a07bb4b49ce2f5672b0a7c41d788 (diff)
downloadwebrtc-9bbfe9e5e09e12ea78048c610de85aeb5970176e.tar.gz
dcsctp: Fix data race in debug logging
The variable instance_count might be accessed from multiple threads when different PeerConnectionFactory objects are used, which may create multiple network threads. This is a pattern mostly noticed in tests. This fixes issues with logging when run under TSAN, it should not have any production impact. Bug: chromium:1243702 Change-Id: Iab1412a7907545811a309cab27a3ae23b4718606 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/251983 Auto-Submit: Florent Castelli <orphis@webrtc.org> Reviewed-by: Victor Boivie <boivie@google.com> Commit-Queue: Florent Castelli <orphis@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36045}
Diffstat (limited to 'media/sctp')
-rw-r--r--media/sctp/dcsctp_transport.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/media/sctp/dcsctp_transport.cc b/media/sctp/dcsctp_transport.cc
index 38d2799f36..0a671ced87 100644
--- a/media/sctp/dcsctp_transport.cc
+++ b/media/sctp/dcsctp_transport.cc
@@ -10,6 +10,7 @@
#include "media/sctp/dcsctp_transport.h"
+#include <atomic>
#include <cstdint>
#include <limits>
#include <utility>
@@ -126,7 +127,7 @@ DcSctpTransport::DcSctpTransport(rtc::Thread* network_thread,
socket_->HandleTimeout(timeout_id);
}) {
RTC_DCHECK_RUN_ON(network_thread_);
- static int instance_count = 0;
+ static std::atomic<int> instance_count = 0;
rtc::StringBuilder sb;
sb << debug_name_ << instance_count++;
debug_name_ = sb.Release();