<p>I have opensips and opensips-b2bua-module modules of version 1.11.5-2~1.gbp1f5df1 installed on Debian Wheezy.</p>

<p>For test purposes I use very simplified opensips.cfg implementing top hiding scenario to connect to FreeSWITCH-based IVR:</p>

<pre><code>route {
    if (is_method("INVITE")) {
        b2b_init_request("top hiding");
    }
}
</code></pre>

<ul>
<li>After successful call establishment UAC sends INFO and re-INVITE packets in very short period of time. </li>
<li>Upon receiving INFO, opensips correctly sends it to B-leg (towards FreeSWITCH).</li>
<li>Then re-INVITE packet arrives from UAC before INFO answer received.</li>
<li>Opensips answers "491 Request Pending" for packet INFO and inspite of error sends re-INVITE towards FreeSWITCH.</li>
<li>Opensips receives "200 OK" for INFO from FreeSWITCH and got error "ERROR:b2b_entities:b2b_send_reply: Mismatch between the method in tm[16] and the method to send reply to[1]"</li>
<li>Opensips receives "200 OK" for re-INVITE and passes it to UAC</li>
</ul>

<p>Please find call flow below</p>

<pre><code>UAC                      Opensips          FreeSWITCH
 |----------INVITE(1)-------&gt;|                  |
 |&lt;-------100 Trying(1)------|                  |
 |                           |-----INVITE(1)---&gt;|
 |                           |&lt;--100 Trying(1)--|
 |                           |&lt;----200 OK(1)----|
 |&lt;---------200 OK(1)--------|                  |
 |------------ACK(1)--------&gt;|                  |
 |                           |------ACK(1)-----&gt;|

================Call established=================

 |-----------INFO(2)--------&gt;|                  |
 |----------INVITE(3)-------&gt;|                  |
 |                           |------INFO(2)----&gt;|
 |&lt;--491 Request Pending(2)--|                  |
 |&lt;-------100 Trying(3)------|                  |
 |                           |-----INVITE(3)---&gt;|
 |                           |&lt;--100 Trying(3)--|
 |                           |&lt;----200 OK(2)----|
 |                           |                  |
                            ERROR:b2b_entities:b2b_send_reply: 
                            Mismatch between the method in tm[16] 
                            and the method to send reply to[1]

 |                           |&lt;----200 OK(3)----|
 |&lt;---------200 OK(3)--------|                  |
 |                           |                  |
Never receive answer
for INFO  
</code></pre>

<p>I see two issues here </p>

<ul>
<li>"491 Request Pending" should be answered for re-INVITE packet, not for INFO</li>
<li>re-INVITE should NOT be passed to B-leg</li>
</ul>

<p>So correct call flow should look like this</p>

<pre><code>UAC                      Opensips          FreeSWITCH
 |----------INVITE(1)-------&gt;|                  |
 |&lt;-------100 Trying(1)------|                  |
 |                           |-----INVITE(1)---&gt;|
 |                           |&lt;--100 Trying(1)--|
 |                           |&lt;----200 OK(1)----|
 |&lt;---------200 OK(1)--------|                  |
 |------------ACK(1)--------&gt;|                  |
 |                           |------ACK(1)-----&gt;|

================Call established=================

 |-----------INFO(2)--------&gt;|                  |
 |----------INVITE(3)-------&gt;|                  |
 |                           |------INFO(2)----&gt;|
 |&lt;--491 Request Pending(3)--|                  |
 |                           |&lt;----200 OK(2)----|
 |&lt;---------200 OK(2)--------|                  |
 |                           |                  |
</code></pre>

<p>I've tried to make patch to fix issue but I'm not sure if it's correct.<br>
Hope you will find this helpful.</p>

<pre><code>diff --git a/modules/b2b_entities/dlg.c b/modules/b2b_entities/dlg.c
index e656d8b..6798d3d 100644
--- a/modules/b2b_entities/dlg.c
+++ b/modules/b2b_entities/dlg.c
@@ -863,15 +863,17 @@ logic_notify:
                                                LM_DBG("Received another request when the previous "
                                                        "one was in process\n");
                                                str text = str_init("Request Pending");
-                                               if(tmb.t_reply_with_body(dlg-&gt;uas_tran, 491,
+                                               if(tmb.t_reply_with_body(tm_tran, 491,
                                                &amp;text, 0, 0, &amp;to_tag) &lt; 0)
                                                {
                                                        LM_ERR("failed to send reply with tm\n");
                                                }
                                                LM_DBG("Sent reply [491] and unreffed the cell %p\n",
-                                                       dlg-&gt;uas_tran);
+                                                       tm_tran);
                                        }
-                                       tmb.unref_cell(dlg-&gt;uas_tran);
+                                       tmb.unref_cell(tm_tran);
+                                       lock_release(&amp;table[hash_index].lock);
+                                       return SCB_DROP_MSG;
                                }
                                dlg-&gt;uas_tran = tm_tran;
                                LM_DBG("Saved uas_tran=[%p] for dlg[%p]\n", tm_tran, dlg);
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/OpenSIPS/opensips/issues/679">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AFOciUkWiV7SG4mgEr_2Bg_ouDk0H_B3ks5o9hkCgaJpZM4GSD7e.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/OpenSIPS/opensips/issues/679"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>