Skip to content

Commit

Permalink
bug #32799 [HttpKernel] do not stopwatch sections when profiler is di…
Browse files Browse the repository at this point in the history
…sabled (Tobion)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel] do not stopwatch sections when profiler is disabled

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |
| License       | MIT
| Doc PR        |

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. found with #32242

Commits
-------

8718cd1 [HttpKernel] do not stopwatch sections when profiler is disabled
  • Loading branch information
Tobion committed Jul 29, 2019
2 parents aefc7f5 + 8718cd1 commit de490b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Expand Up @@ -42,6 +42,9 @@ protected function preDispatch($eventName, Event $event)
break;
case KernelEvents::TERMINATE:
$token = $event->getResponse()->headers->get('X-Debug-Token');
if (null === $token) {
break;
}
// There is a very special case when using built-in AppCache class as kernel wrapper, in the case
// of an ESI request leading to a `stale` response [B] inside a `fresh` cached response [A].
// In this case, `$token` contains the [B] debug token, but the open `stopwatch` section ID
Expand All @@ -66,12 +69,18 @@ protected function postDispatch($eventName, Event $event)
break;
case KernelEvents::RESPONSE:
$token = $event->getResponse()->headers->get('X-Debug-Token');
if (null === $token) {
break;
}
$this->stopwatch->stopSection($token);
break;
case KernelEvents::TERMINATE:
// In the special case described in the `preDispatch` method above, the `$token` section
// does not exist, then closing it throws an exception which must be caught.
$token = $event->getResponse()->headers->get('X-Debug-Token');
if (null === $token) {
break;
}
try {
$this->stopwatch->stopSection($token);
} catch (\LogicException $e) {
Expand Down
Expand Up @@ -61,15 +61,13 @@ public function testStopwatchCheckControllerOnRequestEvent()
public function testStopwatchStopControllerOnRequestEvent()
{
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')
->setMethods(['isStarted', 'stop', 'stopSection'])
->setMethods(['isStarted', 'stop'])
->getMock();
$stopwatch->expects($this->once())
->method('isStarted')
->willReturn(true);
$stopwatch->expects($this->once())
->method('stop');
$stopwatch->expects($this->once())
->method('stopSection');

$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch);

Expand Down

0 comments on commit de490b4

Please sign in to comment.