Fix potential deadlock in VideoAnalyzer
Bug: webrtc:11809
Change-Id: I9b037f7bc06ff8e5b5b6abf3467d7a3825c212e8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/180520
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31807}
diff --git a/video/video_analyzer.cc b/video/video_analyzer.cc
index 365a089..a1174b5 100644
--- a/video/video_analyzer.cc
+++ b/video/video_analyzer.cc
@@ -456,9 +456,15 @@
}
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();