Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 26989b2

Browse filesBrowse files
bug #47857 [HttpKernel] Fix empty request stack when terminating with exception (krzyc)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [HttpKernel] Fix empty request stack when terminating with exception | Q | A | ------------- | --- | Branch? | 4.4, 5.4, 6.0, 6.1, 6.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #47577 | License | MIT | Doc PR | After symfony/symfony#47358 the RequestStack is empty when request terminates with exception, which prevents SecurityDataCollector to generate logout URL and generates fatal error. Commits ------- e4d6e7b4ba [HttpKernel] Fix empty request stack when terminating with exception
2 parents 9a34f1a + 3f61170 commit 26989b2
Copy full SHA for 26989b2

File tree

Expand file treeCollapse file tree

2 files changed

+28
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-1
lines changed

‎HttpKernel.php

Copy file name to clipboardExpand all lines: HttpKernel.php
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,17 @@ public function terminateWithException(\Throwable $exception, Request $request =
112112
throw $exception;
113113
}
114114

115-
$response = $this->handleThrowable($exception, $request, self::MASTER_REQUEST);
115+
if ($pop = $request !== $this->requestStack->getMasterRequest()) {
116+
$this->requestStack->push($request);
117+
}
118+
119+
try {
120+
$response = $this->handleThrowable($exception, $request, self::MASTER_REQUEST);
121+
} finally {
122+
if ($pop) {
123+
$this->requestStack->pop();
124+
}
125+
}
116126

117127
$response->sendHeaders();
118128
$response->sendContent();

‎Tests/HttpKernelTest.php

Copy file name to clipboardExpand all lines: Tests/HttpKernelTest.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\HttpFoundation\Response;
2121
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
2222
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
23+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
2324
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
2425
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
2526
use Symfony\Component\HttpKernel\Exception\ControllerDoesNotReturnResponseException;
@@ -340,6 +341,22 @@ public function testTerminate()
340341
$this->assertEquals($response, $capturedResponse);
341342
}
342343

344+
public function testTerminateWithException()
345+
{
346+
$dispatcher = new EventDispatcher();
347+
$requestStack = new RequestStack();
348+
$kernel = $this->getHttpKernel($dispatcher, null, $requestStack);
349+
350+
$dispatcher->addListener(KernelEvents::EXCEPTION, function (ExceptionEvent $event) use (&$capturedRequest, $requestStack) {
351+
$capturedRequest = $requestStack->getCurrentRequest();
352+
$event->setResponse(new Response());
353+
});
354+
355+
$kernel->terminateWithException(new \Exception('boo'), $request = Request::create('/'));
356+
$this->assertSame($request, $capturedRequest);
357+
$this->assertNull($requestStack->getCurrentRequest());
358+
}
359+
343360
public function testVerifyRequestStackPushPopDuringHandle()
344361
{
345362
$request = new Request();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.