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

Skip to content

[2.1] issues with StopWatch and HttpCache with ESI #6227

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
lsmith77 opened this issue Dec 7, 2012 · 20 comments
Closed

[2.1] issues with StopWatch and HttpCache with ESI #6227

lsmith77 opened this issue Dec 7, 2012 · 20 comments

Comments

@lsmith77
Copy link
Contributor

lsmith77 commented Dec 7, 2012

i have a page with a single ESI block. when the cache is empty the page is rendered properly. on the second request i always end up with:

LogicException: The section "50c202c895f34" has been started at an other level and can not be opened.

    in /vagrant/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/Stopwatch.php line 41
    at Stopwatch->openSection('50c202c895f34') in /vagrant/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/ContainerAwareTraceableEventDispatcher.php line 72
    at ContainerAwareTraceableEventDispatcher->dispatch('kernel.terminate', object(PostResponseEvent)) in /vagrant/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 90
    at HttpKernel->terminate(object(Request), object(Response)) in /vagrant/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 155
    at Kernel->terminate(object(Request), object(Response)) in /vagrant/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php line 227
    at HttpCache->terminate(object(Request), object(Response)) in /vagrant/web/app_dev.php line 31

on the master request i have set:

        $response = $this->templating->renderResponse($contentTemplate, $params);
        $response->setCache(array('s_maxage' => 300, 'public' => true));

on the controller for the ESI response it doesnt matter if i set cache headers or not or if i set the response to private or public. i always end up with the above Exception.

it seems like on a cache hit gets confused about the stopwatch levels.

@fabpot
Copy link
Member

fabpot commented Dec 11, 2012

I'm not able to reproduce the issue. I've tried with current Symfony 2.1 and a simple controller like what you describe. You have something else going on. Here is what I've done on a clean Symfony SE: https://github.com/fabpot/symfony-standard/compare/symfony:2.1...fabpot:PR6227.patch

@lsmith77
Copy link
Contributor Author

ok .. after a while of debugging i found that the issue was caused by FOSRestBundle and I fixed the issue with:
FriendsOfSymfony/FOSRestBundle@4601376

however i am not sure why this is causing an issue. i guess it must be related to this line here https://github.com/symfony/HttpFoundation/blob/master/Response.php#L143 being undone.

@lsmith77
Copy link
Contributor Author

hmm no .. when i was cleaning up my setup the issue returned .. debugging this again.

@lsmith77
Copy link
Contributor Author

i tried everything to isolate the issue in my project or reproduce it in your SE fork .. i still dont know what is causing this.

@Sybio
Copy link

Sybio commented Dec 14, 2012

I have the same bug, I indeed found that since Symfony 2.1, ESI (with standalone true) can't get along with a main cached action (with public shared cache)...

This bug doesn't exist in the previous SF versions (work fine on 2.0.11) !

Remark @fabpot : the bug only appears when returning on the page plural times (the first time, all is well displayed, the page and ESI work fine ! The second or third time, design is broken and the error displayed)

Example when the bug appeared:

Main action:

   /**
     * @Route("/", name="sybiowebsite_main_index")
     * @Cache(smaxage="100")
     * @Template()
     */
    public function indexAction()
    {
        return array();
    }

template -> SybioWebsiteBundle:Main:index.html.twig:

   {% render "SybioWebsiteBundle:Category:listEsi" with {}, {'standalone': true} %}

The error, it appears only if standalone is set to true:

LogicException: The section "50cb77cfaf8eb" has been started at an other level and can not be opened.

This is a problem because I can't cache (http cache) entirely my websites :s

@lsmith77
Copy link
Contributor Author

@Sybio habe you managed to setup an SE fork where this issue is reproducable?

@fabpot
Copy link
Member

fabpot commented Jan 9, 2013

@Sybio That would help a lot if you give us a fork of the Symfony Standard Edition with code that exhibit the issue (like I did above in a previous comment).

@MichaelHindley
Copy link

LogicException: The section "50ffddbd7d7cf" has been started at an other level and can not be opened.

Getting this on every app_dev.php page after running composer update for master branch today.

@fabpot
Copy link
Member

fabpot commented Jan 23, 2013

@NihilNovi: I've just tried with master and I still don't have the issue. Can you list the bundles you are using?

@MichaelHindley
Copy link

"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "2.2.*",
    "doctrine/orm": ">=2.2.3,<2.4-dev",
    "doctrine/doctrine-bundle": "1.2.*",
    "twig/extensions": "1.0.*",
    "symfony/assetic-bundle": "2.1.*",
    "symfony/swiftmailer-bundle": "2.2.*",
    "symfony/monolog-bundle": "2.2.*",
    "sensio/distribution-bundle": "2.2.*",
    "sensio/framework-extra-bundle": "2.2.*",
    "sensio/generator-bundle": "2.2.*",
    "jms/security-extra-bundle": "1.4.*",
    "jms/di-extra-bundle": "1.3.*",
    "jms/serializer-bundle": "0.9",
    "friendsofsymfony/rest-bundle": "0.10.0"
},

I manged to make it go away by disabling the profiler, clearing cache and enabling it again after building the cache.

@yellow1912
Copy link

I have the same issue when I enable profiler and turn on debug. I suspect it's because of my specific setup however. I'm running it on a very old system (hybrid) so I suspect that I missed some dispatches which causes the total number of stopwatch start+stop to mis-match?

@bamarni
Copy link
Contributor

bamarni commented Feb 6, 2013

I have the same issue, unfortunately I can't reproduce this in a sandbox app...

I can confirm it's because of an esi, for example this makes the error appear :

{% render(controller("MyMainBundle:Menu:main")), { strategy: 'esi' } %}

And switching to "inline" fixes it, I've also made the action in quesiton only returning a 200 'Hello' response and the bug is still here so I don't think it's because of something wrong at action level.

@bamarni
Copy link
Contributor

bamarni commented Feb 7, 2013

Are we all using vagrant in here? I've just noticed it doesn't occur with wamp.

@lsmith77
Copy link
Contributor Author

lsmith77 commented Feb 7, 2013

yes. I was using vagrant in this setup

@MichaelHindley
Copy link

I'm using 64bit wamp running php 5.4.3.

@bamarni
Copy link
Contributor

bamarni commented Feb 9, 2013

@lsmith77 @NihilNovi : #7033 should do the trick :)

@lsmith77
Copy link
Contributor Author

i am no vacation this week ..

@bamarni
Copy link
Contributor

bamarni commented Feb 14, 2013

@lsmith77 nevermind, it has been closed anyway, @fabpot is working on a fix, just enjoy your holidays ;)

@fabpot
Copy link
Member

fabpot commented Feb 14, 2013

For the record, I'm not working on a fix, I was just saying that your PR was not good.

@bamarni
Copy link
Contributor

bamarni commented Feb 17, 2013

@fabpot : ok, just FYI, and if someone wants to take a look at this, the patch you've previously made (https://github.com/fabpot/symfony-standard/compare/symfony:2.1...fabpot:PR6227.patch) was correct, it makes this issue reproductible.

You probably didn't see the exception because it occurs on kernel.terminate event, when the response has already been sent, you couldn't see it in the logs neither because currently symfony can't log fatal errors (it's an uncaught exception), only display them.

fabpot added a commit that referenced this issue 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 as completed Feb 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants