Requests are pushed onto the request stack twice, popped once

Created on 11 November 2015, over 9 years ago
Updated 19 April 2023, about 2 years ago

Problem/Motivation

  • Symfony\Component\HttpKernel\HttpKernel::handleRaw() pushes $request onto the stack and Symfony\Component\HttpKernel\HttpKernel::finishRequest() pops it.
  • DrupalKernel::preHandle() also pushes $request onto the stack, but there's no matching pop.
  • As a result, at the conclusion of a subrequest, the stack still contains the subrequest. One consequence of this is that on a comment permalink page (e.g., /comment/1), drupalSettings.path.currentPath is 'node/1' instead of 'comment/1'. I don't know if there are other, more important, consequences.

Proposed resolution

Introduce RequestStackWrapper decorator for request_stack and pass it to http_kernel.basic instead of symfovy's one to be able to remove it in additional subscriber StackMiddlewareSubscriber runnig after KernelDestructionSubscriber

Sum-up in #2613044-85: Requests are pushed onto the request stack twice, popped once β†’

Remaining tasks

Get RTBC and commit

User interface changes

no

API changes

2 new services for core: decorator of request stack and stack clean-up after kernel destroyed

Data model changes

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
Request processingΒ  β†’

Last updated 5 days ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States effulgentsia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine voleger Ukraine, Rivne

    Rerolled.
    Changes affected by CR Drupal\Core\Http\RequestStack is deprecated β†’
    Created MR

  • Pipeline finished with Failed
    over 1 year ago
    Total: 503s
    #69227
  • Status changed to Needs work over 1 year ago
  • πŸ‡«πŸ‡·France andypost

    Thank you, some tests failed and it needs CR

    As there's many+1 in related issue it could be follow-up to prevent popping of ech request twice

  • Status changed to Needs review over 1 year ago
  • Pipeline finished with Failed
    over 1 year ago
    Total: 710s
    #70014
  • Pipeline finished with Failed
    over 1 year ago
    Total: 666s
    #70025
  • Pipeline finished with Failed
    over 1 year ago
    Total: 642s
    #70030
  • Status changed to Needs work over 1 year ago
  • πŸ‡«πŸ‡·France andypost

    2 tests still fail

  • First commit to issue fork.
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I've looked at the MR and the current solution is quite confusing for me. I wonder if instead of having a wrapped request stack we can pass in a NULL for the request stack and allow the Symfony HttpKernel to use it's own request stack - separate from Drupals. This would decouple the request stacks which I think might make this make more sense than wrapping.

    Alternatively we could admit the \Symfony\Component\HttpKernel\HttpKernel doesn't work for us and we could copy and maintain the code in a way that does.

  • Merge request !9861Use a different request stack in Symfony β†’ (Open) created by alexpott
  • Pipeline finished with Failed
    8 months ago
    Total: 679s
    #312371
  • Pipeline finished with Failed
    8 months ago
    Total: 148s
    #313513
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    So the idea of just allowing the Symfony code to instantiate its own request stack did not work - see https://git.drupalcode.org/project/drupal/-/merge_requests/9861 - interesting fails.

    I've updated the old MR to pass PHPStan and coding standards on 11.x plus I've made the service it adds private and less useful looking. I'm still not convinced that adding a new service is better than reworking Symfony\Component\HttpKernel\HttpKernel to work the way we want it to.

  • Pipeline finished with Failed
    8 months ago
    Total: 607s
    #313527
  • Pipeline finished with Failed
    8 months ago
    Total: 390s
    #313656
  • Pipeline finished with Failed
    8 months ago
    Total: 388s
    #313692
  • πŸ‡¬πŸ‡§United Kingdom joachim

    > Alternatively we could admit the \Symfony\Component\HttpKernel\HttpKernel doesn't work for us and we could copy and maintain the code in a way that does.

    The fact that we use the Symfony HttpKernel is pretty useful over at ✨ Add drupalGet() to KernelTestBase Active .

  • Status changed to Needs review 20 days ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Hit a pretty gnarly bug from this yesterday on a client project that was making use of sub-requests and cacheable json responses.

    The net result was cache poisoning via the route cache context.

    With a sub-request we push each request to the stack twice but only pop it once, the current route match can end up still pointing at the sub-request rather than the parent request and as a result any cacheable responses that use the route cache context end up with the wrong route name and parameters.

    This lead to a scenario where an anonymous user could request a JSON page that made a subrequest to a regular node page but the JSON page ended up being cached with the node page's route params. After that any request to the node page was getting the cached JSON response.

    What's left here?

  • πŸ‡ΊπŸ‡ΈUnited States pwolanin

    What's wrong with the original MR that tries to pop off the extra request?

Production build 0.71.5 2024