Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug] Strange session behaviour #6886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kotsis opened this issue Jan 26, 2013 · 1 comment
Closed

[Bug] Strange session behaviour #6886

kotsis opened this issue Jan 26, 2013 · 1 comment

Comments

@kotsis
Copy link

kotsis commented Jan 26, 2013

I have managed to find a session bug that is easily reproducible.

First you have to enalbe database sessions, i did so by following this guide http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html

Then you can create 2 actions like this:

/**
    * @Route("/lol", name="myroute_lol")
    * 
    */
    public function lolAction()
    {
    $this->container->get('session')->set('testsess', '[email protected]');

    //send an email
    $message = \Swift_Message::newInstance()
        ->setSubject('Test subject')
        ->setFrom('[email protected]')
        ->setTo('[email protected]')
        ->setBody($this->renderView('MyBundle:Default:mail.txt.twig', array('body' => 'some body text')))
    ;
    $this->get('mailer')->send($message);

            return $this->redirect($this->generateUrl('myroute_lol2'));
    }

/**
    * @Route("/lol2", name="myroute_lol2")
    */
public function lol2Action()
    {
    $email = $this->container->get('session')->get('testsess');
        return new Response('email:'.$email);
    }

If you clear you browser cookies then each time you go to the /lol url then you get redirected to /lol2 and the session returns an empty string for session variable 'testsess'
If you refresh /lol2 then the second time it works and shows the correct value.

It has something to do with mail. If you comment out the line where the send() happens then all is ok. It has something to do with not writing the session in the database after the completion of the execution of the action.

I have debugged the swift mail bundle a bit and it seems that when send() is called the mail is saved in memory (spool memory, uses class Swift_MemorySpool), so i suppose mails are sent after the completion of the action, after the action returns, somewhat asynchronously i suppose.

It seems that something happens in the code after the action returns a redirect.
If you change the redirect and simply output something then the session is ok.

This bug has 3 conditions, using mysql sessions, sending an email and then redirecting to another action.
It is reproducible. I hope i didn't cause confusion.

Thank you.

P.S. using symfony 2.1.7

@stof
Copy link
Member

stof commented Jan 26, 2013

Duplicate of #6417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants