Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9d3d07

Browse files
committed
merged branch jfsimon/issue-6227 (PR #7180)
This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #7180). Commits ------- 6a33bc2 [HttpKernel] Fixes AppCache + ESI + Stopwatch problem Discussion ---------- [HttpKernel] Fixes AppCache + ESI + Stopwatch problem 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. | Q | A | ------------- | --- | Bug fix? | yes | Bug mask? | no, does @vicb agree? | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #6227, #6230 I tried to find a better solution than just wrapping thrown exceptions with `try/catch`, but IMHO the #6230 solution from @lsmith77 was in fine the best one. I just added some comments in the code to avoid the WTF reactions while reading it. --------------------------------------------------------------------------- by vicb at 2013-02-25T16:51:51Z @vicb never agrees :) I don't have time to check this deeply now but I would like to see a UT. Could your use case be expressed as "on nested terminate events" ? --------------------------------------------------------------------------- by jfsimon at 2013-02-25T16:58:49Z @vicb If I had an idea on how to write a conclusive test for that, I swear, it would be provided in this PR.
2 parents e534d88 + 4ecc246 commit b9d3d07

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,14 @@ private function preDispatch($eventName, Event $event)
388388
break;
389389
case KernelEvents::TERMINATE:
390390
$token = $event->getResponse()->headers->get('X-Debug-Token');
391-
$this->stopwatch->openSection($token);
391+
// There is a very special case when using builtin AppCache class as kernel wrapper, in the case
392+
// of an ESI request leading to a `stale` response [B] inside a `fresh` cached response [A].
393+
// In this case, `$token` contains the [B] debug token, but the open `stopwatch` section ID
394+
// is equal to the [A] debug token. Trying to reopen section with the [B] token throws an exception
395+
// which must be caught.
396+
try {
397+
$this->stopwatch->openSection($token);
398+
} catch (\LogicException $e) {}
392399
break;
393400
}
394401
}
@@ -410,7 +417,11 @@ private function postDispatch($eventName, Event $event)
410417
break;
411418
case KernelEvents::TERMINATE:
412419
$token = $event->getResponse()->headers->get('X-Debug-Token');
413-
$this->stopwatch->stopSection($token);
420+
// In the special case described in the `preDispatch` method above, the `$token` section
421+
// does not exist, then closing it throws an exception which must be caught.
422+
try {
423+
$this->stopwatch->stopSection($token);
424+
} catch (\LogicException $e) {}
414425
// The children profiles have been updated by the previous 'kernel.response'
415426
// event. Only the root profile need to be updated with the 'kernel.terminate'
416427
// timing informations.

0 commit comments

Comments
 (0)