Skip to content

Commit de490b4

Browse files
committed
bug #32799 [HttpKernel] do not stopwatch sections when profiler is disabled (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
2 parents aefc7f5 + 8718cd1 commit de490b4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ protected function preDispatch($eventName, Event $event)
4242
break;
4343
case KernelEvents::TERMINATE:
4444
$token = $event->getResponse()->headers->get('X-Debug-Token');
45+
if (null === $token) {
46+
break;
47+
}
4548
// There is a very special case when using built-in AppCache class as kernel wrapper, in the case
4649
// of an ESI request leading to a `stale` response [B] inside a `fresh` cached response [A].
4750
// In this case, `$token` contains the [B] debug token, but the open `stopwatch` section ID
@@ -66,12 +69,18 @@ protected function postDispatch($eventName, Event $event)
6669
break;
6770
case KernelEvents::RESPONSE:
6871
$token = $event->getResponse()->headers->get('X-Debug-Token');
72+
if (null === $token) {
73+
break;
74+
}
6975
$this->stopwatch->stopSection($token);
7076
break;
7177
case KernelEvents::TERMINATE:
7278
// In the special case described in the `preDispatch` method above, the `$token` section
7379
// does not exist, then closing it throws an exception which must be caught.
7480
$token = $event->getResponse()->headers->get('X-Debug-Token');
81+
if (null === $token) {
82+
break;
83+
}
7584
try {
7685
$this->stopwatch->stopSection($token);
7786
} catch (\LogicException $e) {

src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@ public function testStopwatchCheckControllerOnRequestEvent()
6161
public function testStopwatchStopControllerOnRequestEvent()
6262
{
6363
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')
64-
->setMethods(['isStarted', 'stop', 'stopSection'])
64+
->setMethods(['isStarted', 'stop'])
6565
->getMock();
6666
$stopwatch->expects($this->once())
6767
->method('isStarted')
6868
->willReturn(true);
6969
$stopwatch->expects($this->once())
7070
->method('stop');
71-
$stopwatch->expects($this->once())
72-
->method('stopSection');
7371

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

0 commit comments

Comments
 (0)