From 3ea3e0c345936911ad7c1ff706355dc95e2132bc Mon Sep 17 00:00:00 2001 From: Ilya Nikolaevskiy Date: Wed, 29 Jul 2020 16:20:13 +0000 Subject: [PATCH] Fix potential deadlock in VideoAnalyzer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:11809 Change-Id: I9b037f7bc06ff8e5b5b6abf3467d7a3825c212e8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/180520 Commit-Queue: Björn Terelius Reviewed-by: Björn Terelius Cr-Commit-Position: refs/heads/master@{#31807} --- video/video_analyzer.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/video/video_analyzer.cc b/video/video_analyzer.cc index 365a089302..a1174b5191 100644 --- a/video/video_analyzer.cc +++ b/video/video_analyzer.cc @@ -456,9 +456,15 @@ bool VideoAnalyzer::IsInSelectedSpatialAndTemporalLayer( } void VideoAnalyzer::PollStats() { + // Do not grab |comparison_lock_|, before |GetStats()| completes. + // Otherwise a deadlock may occur: + // 1) |comparison_lock_| is acquired after |lock_| + // 2) |lock_| is acquired after internal pacer lock in SendRtp() + // 3) internal pacer lock is acquired by GetStats(). + Call::Stats call_stats = call_->GetStats(); + MutexLock lock(&comparison_lock_); - Call::Stats call_stats = call_->GetStats(); send_bandwidth_bps_.AddSample(call_stats.send_bandwidth_bps); VideoSendStream::Stats send_stats = send_stream_->GetStats();