<p dir="auto">I have managed to find a session bug that is easily reproducible.</p>
<p dir="auto">First you have to enalbe database sessions, i did so by following this guide <a href="http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html" rel="nofollow">http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html</a></p>
<p dir="auto">Then you can create 2 actions like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/**
    * @Route(&quot;/lol&quot;, name=&quot;myroute_lol&quot;)
    * 
    */
    public function lolAction()
    {
    $this-&gt;container-&gt;get('session')-&gt;set('testsess', 'aasasaasasas@ooo.com');

    //send an email
    $message = \Swift_Message::newInstance()
        -&gt;setSubject('Test subject')
        -&gt;setFrom('test@mail.com')
        -&gt;setTo('something@test.gr')
        -&gt;setBody($this-&gt;renderView('MyBundle:Default:mail.txt.twig', array('body' =&gt; 'some body text')))
    ;
    $this-&gt;get('mailer')-&gt;send($message);

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

/**
    * @Route(&quot;/lol2&quot;, name=&quot;myroute_lol2&quot;)
    */
public function lol2Action()
    {
    $email = $this-&gt;container-&gt;get('session')-&gt;get('testsess');
        return new Response('email:'.$email);
    }"><pre class="notranslate"><code class="notranslate">/**
    * @Route("/lol", name="myroute_lol")
    * 
    */
    public function lolAction()
    {
    $this-&gt;container-&gt;get('session')-&gt;set('testsess', 'aasasaasasas@ooo.com');

    //send an email
    $message = \Swift_Message::newInstance()
        -&gt;setSubject('Test subject')
        -&gt;setFrom('test@mail.com')
        -&gt;setTo('something@test.gr')
        -&gt;setBody($this-&gt;renderView('MyBundle:Default:mail.txt.twig', array('body' =&gt; 'some body text')))
    ;
    $this-&gt;get('mailer')-&gt;send($message);

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

/**
    * @Route("/lol2", name="myroute_lol2")
    */
public function lol2Action()
    {
    $email = $this-&gt;container-&gt;get('session')-&gt;get('testsess');
        return new Response('email:'.$email);
    }
</code></pre></div>
<p dir="auto">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'<br>
If you refresh /lol2 then the second time it works and shows the correct value.</p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">It seems that something happens in the code after the action returns a redirect.<br>
If you change the redirect and simply output something then the session is ok.</p>
<p dir="auto">This bug has 3 conditions, using mysql sessions, sending an email and then redirecting to another action.<br>
It is reproducible. I hope i didn't cause confusion.</p>
<p dir="auto">Thank you.</p>
<p dir="auto">P.S. using symfony 2.1.7</p>
<p dir="auto">Hi,</p>
<p dir="auto">probably I have found an issue in using form with Twig templates. I have a base Twig template source with which I check if a block is filled deeper in the hierarchy.</p>
<div class="highlight highlight-text-html-django notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# WebBundle:Default:base.html.twig
{% if block('body') is not empty %}
    {% block body %}{% endblock %}
{% endif %}"><pre class="notranslate"># WebBundle:Default:base.html.twig
<span class="pl-e">{%</span> <span class="pl-k">if</span> <span class="pl-k">block</span>(<span class="pl-s">'body'</span>) <span class="pl-s">is</span> <span class="pl-k">not</span> <span class="pl-s">empty</span> <span class="pl-e">%}</span>
    <span class="pl-e">{%</span> <span class="pl-k">block</span> <span class="pl-s">body</span> <span class="pl-e">%}{%</span> <span class="pl-k">endblock</span> <span class="pl-e">%}</span>
<span class="pl-e">{%</span> <span class="pl-k">endif</span> <span class="pl-e">%}</span></pre></div>
<p dir="auto">The following is the Twig template that inherit the previous template:</p>
<div class="highlight highlight-text-html-django notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# WebBundle:Default:form.html.twig
{% extends 'WebBundle:Default:base.html.twig' %}
{% block body %}
    {{ form(form) }}
{% endblock %}"><pre class="notranslate"># WebBundle:Default:form.html.twig
<span class="pl-e">{%</span> <span class="pl-k">extends</span> <span class="pl-s">'WebBundle:Default:base.html.twig'</span> <span class="pl-e">%}</span>
<span class="pl-e">{%</span> <span class="pl-k">block</span> <span class="pl-s">body</span> <span class="pl-e">%}</span>
    {{ form(form) }}
<span class="pl-e">{%</span> <span class="pl-k">endblock</span> <span class="pl-e">%}</span></pre></div>
<p dir="auto">In this way the form is left empty: ONLY THE <code class="notranslate">&lt;FORM/&gt;</code> TAG IS PRINTED, but not its content.</p>
<p dir="auto">If I remove the condition in the first file it works properly, rendering the required form with all the fields, as expected.</p>
<div class="highlight highlight-text-html-django notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# WebBundle:Default:base.html.twig
{% block body %}{% endblock %}"><pre class="notranslate"># WebBundle:Default:base.html.twig
<span class="pl-e">{%</span> <span class="pl-k">block</span> <span class="pl-s">body</span> <span class="pl-e">%}{%</span> <span class="pl-k">endblock</span> <span class="pl-e">%}</span></pre></div>
<p dir="auto">Thank you.</p>