Receiving the following errors upon recent install.
RuntimeException: Failed to start the session because headers have already been sent by "/home/mysite/www/vendor/symfony/http-foundation/Response.php" at line 361. in Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start() (line 145 of /home/mysite/www/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php) #0 /home/mysite/www/core/lib/Drupal/Core/Session/SessionManager.php(164): Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start() #1 /home/mysite/www/core/lib/Drupal/Core/Session/SessionManager.php(195): Drupal\Core\Session\SessionManager->startNow() #2 /home/mysite/www/vendor/symfony/http-foundation/Session/Session.php(196): Drupal\Core\Session\SessionManager->save() #3 /home/mysite/www/core/lib/Drupal/Core/StackMiddleware/Session.php(60): Symfony\Component\HttpFoundation\Session\Session->save() #4 /home/mysite/www/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #5 /home/mysite/www/core/modules/ban/src/BanMiddleware.php(50): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #6 /home/mysite/www/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #7 /home/mysite/www/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #8 /home/mysite/www/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #9 /home/mysite/www/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #10 /home/mysite/www/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #11 {main}.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | reroll_diff_6_8.txt | 1.11 KB | mohit_aghera |
| #8 | fix-php-error-on-redirect-3087929-8.patch | 553 bytes | mohit_aghera |
| #6 | fix-php-error-on-redirect-3087929-6.patch | 648 bytes | gmaka |
| #4 | 3087929-fix-php-error-on-redirect.patch | 478 bytes | nicholasthompson |
Issue fork search404-3087929
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
nicholasthompsonI'm getting the same thing on one of our sites.
Using curl, if I hit the homepage, its fine. If I hit `/search?terms=test`, it's fine. If I hit `/test` I get a 301 redirect and the location is `/search?terms=test`, however I now have 2 rows in Watchdog. One is recording the 404, the other is recording the exact stack trace reported above.
Commonly, this error is caused by a <?php tag having whitespace before it, or a closing one having whitespace after it...
Comment #3
nicholasthompsonAh.. in search404Goto... Drop the `->send()` on the return:
This stops the error and the redirect still works..
Comment #4
nicholasthompsonPatch attached
Comment #5
reevo commentedPatch in #4 resolves the issue for me. Thank you! :)
Comment #6
gmaka commented#4 patch fixed the error, but then wasn't redirecting me to my custom path.
Comment #7
ronald van belzen commentedRemoving the send() causes the same issue as reported by gmaka in #6.
Comment #8
mohit_aghera commentedRe-roll the last patch for 2.x branch.
Comment #9
robcarrPatch #8 worked for me.
+1 for RTBC
Comment #10
anybodyConfirming this issue still exists in 2.x and popping up on all our projects. It fills up logs and leads to unexpected functionality. So setting the priority to major.
I'll have a look at the different patches and check, which one is correct.
Comment #11
anybodySo this is interesting. There are several approaches above.
There are also similar issues in other modules like:
In general
would be correct instead of:
to return in the controller. For example, see https://drupalsun.com/philipnorton42/2022/05/22/drupal-9-correct-way-red...
But that doesn't seem to work as I think this comes too late or is overwritten by a core redirect for 404?
There's also a discussion on exactly this topic:
https://drupal.stackexchange.com/questions/138697/what-function-method-c...
I tried
but that leads to the same error as before.
I also tried the implementation from https://blog.ricovandevin.com/redirecting-to-a-specified-destination-in-... but doesn't really seem to make much sense here.
TL;DR:
The correct solution is #8:
It redirects as expected and doesn't lead to any unwanted side-effects. I'll prepare a MR for 2.x with the code, so hopefully this can be merged asap!
Comment #13
anybodyMR!6 ready for review. Based on #6 and #8 for credits.
Could someone here be so nice to review this?
Comment #14
grevil commentedLGTM!
Works as expected and fixes the Problem! RTBC +1.
Comment #16
emilymathew commentedSorry for the late response. This is merged. Thank you...
As this is an urgent issue., released new version 2.1.2 with this change.
Thank you..
Comment #17
martijn de wit