symfony: Symfony 6.3@dev Unexpected ini_set(): Session ini settings cannot be changed after headers have already been sent

Symfony version(s) affected

6.3.0@dev (6.2.*@dev works)

Description

Something seems to be merged into Symfony 6.3 branch which currently let our CI fail on it with:

Warning PHP Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /home/runner/work/sulu/sulu/vendor/symfony/http-foundation/Session/Storage/Handler/NativeFileSessionHandler.php on line 48
PHP Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /home/runner/work/sulu/sulu/vendor/symfony/http-foundation/Session/Storage/Handler/NativeFileSessionHandler.php on line 49

So it looks some changes in the Session handling. Not sure what it could be, shortly looked at the merged Pull Requests I didn’t see why it is happening.

I tested out 6.2.*@dev there all seems to work still like expected.

If somebody have a hint which PR could have introduced the error let me know, happy to test it out.

How to reproduce

git clone git@github.com:sulu/sulu.git
cd sulu

composer config minimum-stability dev
composer update

env DATABASE_URL="mysql://root:ChangeMe@127.0.0.1:3306/sulu?serverVersion=8.0.27&charset=utf8mb4" composer bootstrap-test-env
env DATABASE_URL="mysql://root:ChangeMe@127.0.0.1:3306/sulu?serverVersion=8.0.27&charset=utf8mb4" composer test

Possible Solution

Workaround see: https://github.com/symfony/symfony/issues/49387#issuecomment-1600546860

Additional Context

The change need to be somewhere between Januaray 25 and February 6 and only Symfony 6.3:

Bildschirmfoto 2023-02-15 um 11 33 19

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 23 (22 by maintainers)

Commits related to this issue

Most upvoted comments

yes if no one is ont it already, I would be glad to have a look on it

Why I think it would be good if the PDOSessionListener is only registered when PDO session is used. I currently found a workaround to fix the issue which did only appear with the SuluTestKernel (used by bundles not projects). I had to manually setting the handler_id: null e.g.:

framework:
    session:
        storage_factory_id: session.storage.factory.native
        handler_id: ~ # this was missing

when@test:
    session:
        storage_factory_id: session.storage.factory.mock_file
        handler_id: ~ # this was missing

This way the error seems to disappear.

I propose renaming all *Subscriber to *Listener, and to deprecate MessengerTransportDoctrineSchemaSubscriber, DoctrineDbalCacheAdapterSchemaSubscriber and RememberMeTokenProviderDoctrineSchemaSubscriber (making them extend their corresponding *Listener)

Doctrine\Common\EventSubscriber should be banned from the bridge because it forces instantiating the event listeners (and their deps) even if they are never called.