From 9bbfe9e5e09e12ea78048c610de85aeb5970176e Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Mon, 21 Feb 2022 14:39:47 +0100 Subject: [PATCH] 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 Reviewed-by: Victor Boivie Commit-Queue: Florent Castelli Cr-Commit-Position: refs/heads/main@{#36045} --- media/sctp/dcsctp_transport.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 #include #include #include @@ -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 instance_count = 0; rtc::StringBuilder sb; sb << debug_name_ << instance_count++; debug_name_ = sb.Release();