From b3d062ed3f342bd75a6e5ab5fdac01781a673aa4 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Mon, 29 Jul 2019 16:24:16 +0200 Subject: [PATCH] [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 --- .../HttpKernel/Debug/TraceableEventDispatcher.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php index ddf4fa7cecf05..c265b6010dacf 100644 --- a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php @@ -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 @@ -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) {