From aba45a56220ff49c5bffceb366021f09f0ee088e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Mon, 25 Feb 2013 17:11:33 +0100 Subject: [PATCH 1/2] [HttpKernel] fixed AppCache+ESI+Stopwatch problem --- .../HttpKernel/Debug/TraceableEventDispatcher.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php index adbd4969abc88..a22f84c1ace8f 100644 --- a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php @@ -388,7 +388,14 @@ private function preDispatch($eventName, Event $event) break; case KernelEvents::TERMINATE: $token = $event->getResponse()->headers->get('X-Debug-Token'); - $this->stopwatch->openSection($token); + // There is a very special case when using builtin 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 + // is equal to the [A] debug token. Trying to reopen section with the [B] token throws an exception + // which must be caught. + try { + $this->stopwatch->openSection($token); + } catch (\LogicException $e) {} break; } } @@ -410,7 +417,11 @@ private function postDispatch($eventName, Event $event) break; case KernelEvents::TERMINATE: $token = $event->getResponse()->headers->get('X-Debug-Token'); - $this->stopwatch->stopSection($token); + // In the special case described in th `preDispatch` method above, the `$token` section + // does not exist, then closing it throws an exception which must be caught. + try { + $this->stopwatch->stopSection($token); + } catch (\LogicException $e) {} // The children profiles have been updated by the previous 'kernel.response' // event. Only the root profile need to be updated with the 'kernel.terminate' // timing informations. From 98f56fe6f2f9a0f7402c4f5842df359a2eadd189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Mon, 25 Feb 2013 17:43:36 +0100 Subject: [PATCH 2/2] [HttpKernel] fixed a typo --- .../Component/HttpKernel/Debug/TraceableEventDispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php index a22f84c1ace8f..fe77e47451fa6 100644 --- a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php @@ -417,7 +417,7 @@ private function postDispatch($eventName, Event $event) break; case KernelEvents::TERMINATE: $token = $event->getResponse()->headers->get('X-Debug-Token'); - // In the special case described in th `preDispatch` method above, the `$token` section + // 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. try { $this->stopwatch->stopSection($token);