Review main Abandoned

85224[BUGFIX] Use new container instance for sub request in PageContentErrorHandler

Torben Hansen CR 0 V -1 Easy +6 −0 updated 01/12/26, 09:01

Commit message

When a configured `PageContentErrorHandler` performs a sub request to
fetch the content of the error page, it can occur that the
`PageRenderer` singleton instance already contains rendered page
content. As an example, this happens when an extbase action throws
a `PropagateResponseException` containing a 404 response.

This patch ensures that a new container instance is created before
the sub request is performed. After handling of the sub request,
the original container is restored.

Review

  • Code review CR 0
  • Verified V -1
    • Christian Weiske -1
    • core-ci -1 CI

Issues 2

Files 1

Review log 2023

  1. Torben Hansen uploaded patch set 1 07/11/24, 12:11

  2. core-ci voted on patch set 1 V +1 07/11/24, 12:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61382

  3. Christian Kuhn commented on patch set 1 CR -1 07/11/24, 18:09

    PageContentErrorHandler.php:144

    a better and more global solution is to retrieve the list of all singleton objects from GU, empty the list, perform the sub request, then reset the list. See class FrameworkState of testing framework for an approach that does similar things.
  4. Torben Hansen commented on patch set 1 07/12/24, 08:22

    PageContentErrorHandler.php:144 Reply

    I tried, but with no success. The `PageRenderer` is not available in `GeneralUtility::getSingletonInstances()`, but is injected using DI as far as I can see. So the `PageRenderer` instance should be removed from DI somehow, but I have no idea how to archive this.
  5. Torben Hansen uploaded patch set 2 CR -1 V +1 07/13/24, 15:23

  6. Torben Hansen commented on patch set 2 07/13/24, 15:27

    PageContentErrorHandler.php:144 Reply

    Used a different approach now and we park the existing container, perform the sub request with a fresh instance of container from `BootService` and finally set the parked container back.
  7. core-ci voted on patch set 2 V +1 07/13/24, 15:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61542

  8. Markus Klein commented on patch set 2 CR +1 07/18/24, 06:23

    Makes sense to me, but reveals yet again, that we are far away from encapsulated (sub) request-handling.
  9. Simon Schaufelberger voted on patch set 2 CR +1 V +1 07/18/24, 07:03

  10. Georg Ringer voted on patch set 2 CR +1 V +1 07/19/24, 06:33

  11. Markus Klein voted on patch set 2 V +1 07/26/24, 07:14

  12. Timo Webler commented on patch set 2 08/14/24, 10:07

    PageContentErrorHandler.php:121 Unresolved

    This does not reset the current container. The bootstrap service generate no new container if already one is available. I implement an nasty workaround for it. I hope the core developers will find an better solution for that. ``` /** * Reset content within page renderer for sub request. * * @see https://forge.typo3.org/issues/103215 */ protected function stashEnvironment(callable $fetcher): ResponseInterface { $parkedTsfe = $GLOBALS['TSFE'] ?? null; $GLOBALS['TSFE'] = null; /** @var BootService $bootService */ $bootService = GeneralUtility::makeInstance(BootService::class); $backup = $bootService->makeCurrent($this->getNewContainer($bootService)); $result = $fetcher(); $GLOBALS['TSFE'] = $parkedTsfe; $bootService->makeCurrent(null, $backup); return $result; } protected function getNewContainer(BootService $bootService): ContainerInterface { $callPrivateMethod = function ($object, $method, ...$args) { $call = function ($method, ...$args) { return $this->$method(...$args); }; $newCall = $call->bindTo($object, get_class($object)); return $newCall($method, ...$args); }; return $callPrivateMethod($bootService, 'prepareContainer'); } ```
  13. Guido Schmechel commented on patch set 2 V +1 09/28/24, 15:31

    I can confirm that this has solved the problem for me. I cannot judge whether the code is good enough in this case.
  14. Benjamin Franzke commented on patch set 2 CR -1 10/01/24, 11:30

    Sorry, but we don't want multiple containers, as we want our services to become stateless. I'm aware that is was too early to use sub-requests for 404, but we should rather fix the page renderer state (intermediate fix would be to use the existing update/set state methods), rather then parking the entire container. -1 for now…
  15. Oliver Hader updated the commit message in patch set 3 CR +1 V +1 10/18/24, 14:02

  16. Christian Weiske commented on patch set 3 09/19/25, 10:44

    So instead of fixing this bug that exists *now*, we'll wait until the holy land is reached some time in the future?
  17. Christian Weiske commented on patch set 3 09/22/25, 09:38

    There is a regression with that patch: https://forge.typo3.org/issues/107515 The list of storages gets reset, and loading a image file from a non-local storage on the error page leads to an exception: > Desired storage "AusDriverAmazonS3" is not in the list of available storages.
  18. Christian Weiske commented on patch set 3 09/22/25, 10:05

    Reply Unresolved

    There is currently no way to reset the page renderer to a clean state from outside. reset() does not reset everything and is protected. Replacing the renderer in the container does not work either: "The "TYPO3\CMS\Core\Page\PageRenderer" service is already initialized, you cannot replace it."
  19. Oliver Klee updated the commit message in patch set 4 09/22/25, 10:25

  20. core-ci voted on patch set 4 V -1 09/22/25, 10:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/85284

  21. Christian Weiske commented on patch set 4 V -1 10/08/25, 16:01

    There is another regression with that patch: When a content element on the 404 page tries to check if the preview context is set, a new exception occurs: ``` TYPO3\CMS\Core\Context\Exception\AspectNotFoundException No aspect named "frontend.preview" found. #0 /vendor/typo3/cms-core/Classes/Context/Context.php(152): TYPO3\CMS\Core\Context\Context::getPropertyFromAspect #1 /vendor/fluidtypo3/flux/Classes/Service/RecordService.php(163): FluidTYPO3\Flux\Service\RecordService::isPreviewContext #2 /vendor/fluidtypo3/flux/Classes/Service/RecordService.php(150): FluidTYPO3\Flux\Service\RecordService::isBackendOrPreviewContext #3 /vendor/fluidtypo3/flux/Classes/Service/RecordService.php(63): FluidTYPO3\Flux\Service\RecordService::getSingle #4 /vendor/fluidtypo3/flux/Classes/Service/WorkspacesAwareRecordService.php(37): FluidTYPO3\Flux\Service\WorkspacesAwareRecordService::getSingle #5 /vendor/fluidtypo3/flux/Classes/ViewHelpers/Form/DataViewHelper.php(98): FluidTYPO3\Flux\ViewHelpers\Form\DataViewHelper::renderStatic ```
  22. Torben Hansen abandoned the change 10/17/25, 13:36

    Container parking is no real solution for this. I'll try to provide an alternative intermediate patch to resolve the problem.
  23. Christian Weiske commented on patch set 4 01/12/26, 09:01