You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**
* @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
The text was updated successfully, but these errors were encountered:
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:
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
The text was updated successfully, but these errors were encountered: