RuntimeException: Failed to start the session because headers have already been sent

Created on 20 May 2024, 6 months ago

Problem/Motivation

Using the Simple XML sitemap view submodule, view pages that have enabled the "Index this display in sitemap Default" in the view settings are getting the following error only for logged-in users:

RuntimeException: Failed to start the session because headers have already been sent by "/var/www/html/vendor/symfony/http-foundation/Response.php" at line 410. in Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start() (line 132 of /var/www/html/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php)
#0 /var/www/html/web/core/lib/Drupal/Core/Session/SessionManager.php(144): Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start()
#1 /var/www/html/web/core/lib/Drupal/Core/Session/SessionManager.php(109): Drupal\Core\Session\SessionManager->startNow()
#2 /var/www/html/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php(311): Drupal\Core\Session\SessionManager->start()
#3 /var/www/html/vendor/symfony/http-foundation/Session/Session.php(222): Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->getBag('attributes')
#4 /var/www/html/vendor/symfony/http-foundation/Session/Session.php(242): Symfony\Component\HttpFoundation\Session\Session->getBag('attributes')
#5 /var/www/html/vendor/symfony/http-foundation/Session/Session.php(69): Symfony\Component\HttpFoundation\Session\Session->getAttributeBag()
#6 /var/www/html/web/core/modules/views/src/ViewExecutable.php(722): Symfony\Component\HttpFoundation\Session\Session->get('views')
#7 /var/www/html/web/core/modules/views/src/Form/ViewsExposedForm.php(85): Drupal\views\ViewExecutable->getExposedInput()
#8 [internal function]: Drupal\views\Form\ViewsExposedForm->buildForm(Array, Object(Drupal\Core\Form\FormState))
#9 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array(Array, Array)
#10 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(283): Drupal\Core\Form\FormBuilder->retrieveForm('views_exposed_f...', Object(Drupal\Core\Form\FormState))
#11 /var/www/html/web/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php(134): Drupal\Core\Form\FormBuilder->buildForm('\\Drupal\\views\\F...', Object(Drupal\Core\Form\FormState))
#12 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1255): Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm()
#13 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1433): Drupal\views\ViewExecutable->build(NULL)
#14 /var/www/html/web/core/modules/views/views.module(778): Drupal\views\ViewExecutable->execute()
#15 [internal function]: views_get_view_result('general_search', 'page_news', '2')
#16 /var/www/html/web/modules/contrib/simple_sitemap/modules/simple_sitemap_views/src/SimpleSitemapViews.php(319): call_user_func_array('views_get_view_...', Array)
#17 /var/www/html/web/modules/contrib/simple_sitemap/modules/simple_sitemap_views/src/SimpleSitemapViews.php(252): Drupal\simple_sitemap_views\SimpleSitemapViews->addArgumentsToIndexByVariant(Object(Drupal\views\ViewExecutable), 'default', Array, 'page_news')
#18 /var/www/html/web/modules/contrib/simple_sitemap/modules/simple_sitemap_views/src/EventSubscriber/ArgumentCollector.php(83): Drupal\simple_sitemap_views\SimpleSitemapViews->addArgumentsToIndex(Object(Drupal\views\ViewExecutable), Array, 'page_news')
#19 [internal function]: Drupal\simple_sitemap_views\EventSubscriber\ArgumentCollector->onTerminate(Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#20 /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#21 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(115): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...')
#22 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(63): Symfony\Component\HttpKernel\HttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse))
#23 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(688): Drupal\Core\StackMiddleware\StackedHttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse))
#24 /var/www/html/web/index.php(22): Drupal\Core\DrupalKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse))
#25 {main}

Proposed resolution

Based on other issues related to the header error, I tried to check if there was code similar to this comment 🐛 RuntimeException: Failed to start the session because headers have already been sent Closed: works as designed , but it seems that the submodule or the module, in general, does not use RedirectResponse.

Did anyone have a similar problem?

🐛 Bug report
Status

Active

Version

4.1

Component

Code

Created by

🇳🇱Netherlands arccoss Utrecht

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

Comments & Activities

  • Issue created by @arccoss
  • Status changed to Closed: cannot reproduce about 2 months ago
  • 🇷🇺Russia walkingdexter

    I can't reproduce the problem on a fresh install (did a quick debug for the views exposed form). According to the error trace, the problem is related to starting a new session at the end of the request. This can cause many problems and not only for this module. Feel free to reopen if you can provide additional details.

  • 🇳🇱Netherlands arccoss Utrecht

    Thanks for the reply walkingdexter. I can confirm that I can't reproduce this issue anymore.

Production build 0.71.5 2024