Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8718cd1

Browse filesBrowse files
committed
[HttpKernel] do not stopwatch sections when profiler is disabled
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
1 parent 2113e67 commit 8718cd1
Copy full SHA for 8718cd1

File tree

2 files changed

+10
-3
lines changed
Filter options

2 files changed

+10
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php
+9Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php
+1-3Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.