From ccbc216ac5e269ad5481d2f169709fe937003ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Wed, 11 Nov 2020 13:20:12 +0100 Subject: [PATCH] Avoids potential rounding of -inf time delta in TaskQueuePacedSender. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This rounding triggers a dcheck that crashes debug builds. Furtunately, in release mode this does not matter as the resulting value is anyway capped to 0. Unfortunately, it is almost impossible to write a test for this even with simulated time as the conditions needed to trigger this condition includes thread scheduling being slightly off in such a way that an unscheduled process call preempts a scheduled one at a time when sending a sufficiently large padding packet becomes possible - and right after starting a new probe cluster. We should consider updating this class to make unit testing easier. Bug: webrtc:10809 Change-Id: I533e6e716bddc106d11e82a9e3edb4e0035fd21c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192786 Reviewed-by: Per Kjellander Commit-Queue: Erik Språng Cr-Commit-Position: refs/heads/master@{#32589} --- modules/pacing/task_queue_paced_sender.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/pacing/task_queue_paced_sender.cc b/modules/pacing/task_queue_paced_sender.cc index eb8b11bb6e..69ec5457ad 100644 --- a/modules/pacing/task_queue_paced_sender.cc +++ b/modules/pacing/task_queue_paced_sender.cc @@ -224,9 +224,13 @@ void TaskQueuePacedSender::MaybeProcessPackets( // If we're probing and there isn't already a wakeup scheduled for the next // process time, always post a task and just round sleep time down to // nearest millisecond. - time_to_next_process = - std::max(TimeDelta::Zero(), - (next_process_time - now).RoundDownTo(TimeDelta::Millis(1))); + if (next_process_time.IsMinusInfinity()) { + time_to_next_process = TimeDelta::Zero(); + } else { + time_to_next_process = + std::max(TimeDelta::Zero(), + (next_process_time - now).RoundDownTo(TimeDelta::Millis(1))); + } } else if (next_process_time_.IsMinusInfinity() || next_process_time <= next_process_time_ - hold_back_window_) { // Schedule a new task since there is none currently scheduled