Skip to content

Commit

Permalink
Fixes AppCache + ESI + Stopwatch problem
Browse files Browse the repository at this point in the history
  • Loading branch information
jfsimon authored and fabpot committed Feb 25, 2013
1 parent e534d88 commit 4ecc246
Showing 1 changed file with 13 additions and 2 deletions.
Expand Up @@ -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;
}
}
Expand All @@ -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 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);
} 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.
Expand Down

0 comments on commit 4ecc246

Please sign in to comment.