-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Requests leave stopwatch section open #36623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
the toolbar and profiler panel disable to profiler which then does not set the X-Debug-Token. so when the header does not exist, do not call the stopwatch methods with null which violates the contract and does not make sense
This seems to be the commit that introduce the bug. But on the logic of the Stopwatch::stopSection is not good it's just pop the last active section assuming that the id match. There is no check that the start end stop are done in the proper order. public function stopSection(string $id)
{
$this->stop('__section__');
if (1 == \count($this->activeSections)) {
throw new \LogicException('There is no started section to stop.');
}
$this->sections[$id] = array_pop($this->activeSections)->setId($id);
$this->stop('__section__.child');
} |
Hey, thanks for your report! |
Could I get a reply or should I close this? |
If not using the profiler is a workaround, then yes. Otherwise it is still broken. |
@uncaught may I ask what is your workaround ? I have the same issue. |
I think I simply used |
Can you create a small example application that allows to reproduce your issue? |
@jlekowski This is not related to the messenger but the http kernel. I have gave the exact line of the class where the issue is and also pin point the commit where the issue was introduced. Hard to be more clear than that. #36623 (comment) |
True @mpoiriert, that fix did not target the root cause. |
Well, without a reproducer that allows us to debug the issue in more detail I am afraid it's hard to help. |
@xabbuh, a command like this is probably the simplest way to reproduce it (just run <?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Stopwatch\Stopwatch;
class TestCommand extends Command
{
/**
* @var KernelInterface
*/
private $kernel;
/**
* @var Stopwatch
*/
private $stopwatch;
/**
* @param KernelInterface $kernel
*/
public function __construct(KernelInterface $kernel, Stopwatch $stopwatch)
{
$this->kernel = $kernel;
$this->stopwatch = $stopwatch;
parent::__construct('test');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->stopwatch->start('foo');
$this->kernel->handle(new Request(), HttpKernelInterface::SUB_REQUEST);
$this->stopwatch->stop('foo');
return 0;
}
} |
Guys you just have to revert the portion of the commit that touch the file
mention above
…On Thu., Jul. 15, 2021, 3:44 p.m. Jerzy Lekowski, ***@***.***> wrote:
@xabbuh <https://github.com/xabbuh>, a command like this is probably the
simplest way to reproduce it (just run bin/console test).
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;use Symfony\Component\Console\Input\InputInterface;use Symfony\Component\Console\Output\OutputInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpKernel\HttpKernelInterface;use Symfony\Component\HttpKernel\KernelInterface;use Symfony\Component\Stopwatch\Stopwatch;
class TestCommand extends Command
{
/** * @var KernelInterface */
private $kernel;
/** * @var Stopwatch */
private $stopwatch;
/** * @param KernelInterface $kernel */
public function __construct(KernelInterface $kernel, Stopwatch $stopwatch)
{
$this->kernel = $kernel;
$this->stopwatch = $stopwatch;
parent::__construct('test');
}
/** * @param InputInterface $input * @param OutputInterface $output * @return int */
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->stopwatch->start('foo');
$this->kernel->handle(new Request(), HttpKernelInterface::SUB_REQUEST);
$this->stopwatch->stop('foo');
return 0;
}
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#36623 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA73OAD4JTBOSEB3GFTJKY3TX43BBANCNFSM4MTZPHPQ>
.
|
see #42331 for an attempt to fix this, please give it a try and provide some feedback if that PR fixes your issue |
@xabbuh, I tested your fix on my example code and it worked - the section stays open after running a sub-request. |
…dling `kernel.request` events (xabbuh) This PR was merged into the 4.4 branch. Discussion ---------- [HttpKernel] always close open stopwatch section after handling `kernel.request` events | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #36623 | License | MIT | Doc PR | Commits ------- 705f765 always close open stopwatch section after handling kernel.request events
In order for the TimeDataCollector to work properly the X-Debug-Token from the response header needs to be used which was removed in symfony#42331 to fix symfony#36623. Fixes symfony#42804
In order for the `TimeDataCollector` to work properly the `X-Debug-Token` from the response header needs to be used which was removed in symfony#42331 to fix symfony#36623. Fixes symfony#42804
Symfony version(s) affected: 3.4 up till current master
Description
When making a request, the TraceableEventDispatcher opens a section with the Stopwatch, which never gets closed.
This causes a \LogicException when measuring the time of something with an internal requests.
How to reproduce
--> yields
\LogicException('Event "foo" is not started.')
in the last linePossible Solution
Call
stopSection
even if no'X-Debug-Token'
is set in the response headers.The route name might be a neat fallback:
The TraceableEventDispatcher starts the section, it should be responsible for it being closed again, no matter what.
Additional context
This happens running a functional test with phpunit with debug enabled.
The only place where
'X-Debug-Token'
is set seems to be the Profiler - which is probably not enabled during unit tests (at least for us).The text was updated successfully, but these errors were encountered: