Closed
Description
Symfony version(s) affected: ^4.3
How to reproduce
$event = new \Symfony\Component\Stopwatch\StopwatchEvent(0, null, true);
$event->start();
usleep(100000);
$event->stop();
var_dump($event->getDuration());
$event->start();
$event->start();
$event->start();
usleep(100000);
var_dump($event->getDuration());
$event->stop();
var_dump($event->getDuration());
$event->stop();
var_dump($event->getDuration());
Output:
float(104.5)
float(306.80004882812)
float(205.69995117188) // WTF?
float(308.80004882812)
Possible Solution
Bug lives here: https://github.com/symfony/stopwatch/blob/9e2c41817c3e3d506e5db1d052cbfbbc6f685199/StopwatchEvent.php#L184
for ($i = 0; $i < $left; ++$i) {
$index = $stopped + $i;
$periods[] = new StopwatchPeriod($this->started[$index], $this->getNow(), $this->morePrecision);
}
$this->started
contains only active sessions. So $index
calculation is wrong here