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

Skip to content

[HttpKernel] Fixes AppCache + ESI + Stopwatch problem #7180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

jfsimon
Copy link
Contributor

@jfsimon jfsimon commented Feb 25, 2013

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.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/th/the

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lsmith77 thanks, do you find this comment understable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well as understandable as something as complex as this can get i guess :)

@vicb
Copy link
Contributor

vicb commented Feb 25, 2013

@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" ?

@jfsimon
Copy link
Contributor Author

jfsimon commented Feb 25, 2013

@vicb If I had an idea on how to write a conclusive test for that, I swear, it would be provided in this PR.

fabpot added a commit that referenced this pull request Feb 25, 2013
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.
@fabpot fabpot closed this Feb 25, 2013
@vicb
Copy link
Contributor

vicb commented Feb 25, 2013

Jef, my remark (nested or more accurately successive terminate events) was a hint for a test & may be a better fix.

"Jean-François Simon" [email protected] wrote:

@vicb If I had an idea on how to write a conclusive test for that, I
swear, it would be provided in this PR.


Reply to this email directly or view it on GitHub:
#7180 (comment)

@jfsimon
Copy link
Contributor Author

jfsimon commented Feb 25, 2013

Ah okay Victor, I try something, tell me if it matches your idea:

WHEN using AppCache kernel decorator AND esi is enabled
ON receiving a master request (A) containing an esi tag leading to a fresh cached response AND the esi request (B) leads to a stale cached response
THEN the stopwatch component tries to reopen a non existing section
BECAUSE
    the (A) request dont dispatch `kernel.request` and `kernel.response` events
    AND
        the (A) request dispatches `kernel.terminate` event
        BECAUSE the (B) request was processed by the app

This case is really specific and difficult to explain with simplicity.

@vicb
Copy link
Contributor

vicb commented Feb 25, 2013

If you want to use appcache a ft is probably best. Otherwise you should be able to simulate a simpler tc.

The main thing to keep in mind is not the stopwatch issue specifically imo but terminate in general and the diff in behavior with a "real" reverse proxy.

"Jean-François Simon" [email protected] wrote:

Ah okay Victor, I try something, tell me if it matches your idea:

WHEN using AppCache kernel decorator AND esi is enabled
ON receiving a master request (A) containing an esi tag leading to a
fresh cached response AND the esi request (B) leads to a stale cached
response
THEN the stopwatch component tries to reopen a non existing section
BECAUSE
the (A) request dont dispatch kernel.request and kernel.response
events
AND
the (A) request dispatches kernel.terminate event
BECAUSE the (B) request was processed by the app

This case is really specific and difficult to explain with simplicity.


Reply to this email directly or view it on GitHub:
#7180 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants