<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div>Hello Everyone,  Daniel, </div><div><br></div><div>This is directly related to the previous emails on this subject, sent by Guillaume. I am adresing here the exact same issue, we work together.</div><div><br></div><div>The following piece of code is supposed to disconnect the previous call placed by a user:</div><div><br></div><div>We save call-id,totag (if we have 180,183),fromtag,cseq of the INVITE of the previous dialog in memcache and we retrieve them for each call the user is placing.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                                      </span>   if ($avp(saved_totag_of_previous_call)!=$null){</div><div>                                       
                 # the above check should be equivalent with hastotag() on the other call .</div><div><span style="font-size: 10pt;">                                                        if(dlg_get("$avp(saved_previous_call_callid)", "$avp(saved_totag_of_previous_call)", "$avp(saved_fromtag_of_previous_call)"))</span><br></div><div>                                                </div><div>                                                        {</div><div><span style="font-size: 10pt;">       
                                                                 # sending BYEs to the previous dialog originated by this user </span></div><div>                                                                        if (dlg_bye("all"))</div><div>                                                                        {</div><div>                               
                                                 xlog("L_INFO","BYE sent to caller&callee");</div><div><br></div><div>                                                                        } else {</div><div>                                                                                xlog("L_INFO","could not send locally generated BYEs\n");</div><div><br></div><div>                         
                                               }</div><div>                                                                </div><div>                                                                        dlg_get("$ci","$tt","$ft");</div><div>                                        </div><div>                             
                                          <span class="Apple-tab-span" style="white-space:pre">                                                                                      </span># this BYE will be caught in event_route[tm:local-request] where we do some accounting</div><div>                        </div><div>                                                        } else {</div><div>                                                        # # dialog should be in early state  - eg: 183 or 180 has been received</div><div><br></div><div><span class="Apple-tab-span"
 style="white-space:pre">                          </span><span class="Apple-tab-span" style="font-size: 10pt; white-space: pre;">                                                         </span><span style="font-size: 10pt;">          </span><span style="font-size: 10pt;">                                                       xlog("dlg_get() failed - because the dialog was not confirmed\n");</span></div><div>                                                                if (t_cancel_callid("$avp(saved_previous_call_callid)", "$avp(saved_previous_call_invite_cseq)", "22")) {</div><div>                               
                                           xlog("maxcall:transaction cancelled  - i am in call with call-id: $ci  \n");</div><div><span class="Apple-tab-span" style="white-space:pre">                      </span>                                                                        <span class="Apple-tab-span" style="white-space:pre">                                                           </span>  # do stuff here </div><div>                                                                } else {</div><div><br></div><div>         
                                                                 xlog("maxcall:cannot send forced cancel - the previous dialog had a totag - early state \n");  </div><div>                                                                          xlog("maxcall:i am in call with call-id: $ci \n");</div><div>                                                        </div><div>                           
                                     } </div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                                           </span>                                                        <span class="Apple-tab-span" style="white-space:pre">   </span># do stuff here</div><div><span class="Apple-tab-span" style="font-size: 10pt; white-space: pre;">   </span>                                                       <span class="Apple-tab-span" style="font-size: 10pt; white-space: pre;">                                      </span><span style="font-size: 10pt;"> } else
 {</span><br></div><div><br></div><div><br></div><div>                                                         <span class="Apple-tab-span" style="white-space:pre">                                             </span>        # dialog should be in preceeding state - `100 Trying`  was received (`100 Trying` does not have a totag)</div><div>        <span style="font-size: 10pt;">                                                         if (t_cancel_callid("$avp(saved_previous_call_callid)", "$avp(saved_previous_call_invite_cseq)", "22")) {</span></div><div>                               
                                        xlog("maxcall:transaction cancelled . i am in call with call-id: $ci \n");</div><div><span style="font-size: 10pt;">                                                                       # do stuff here </span><br></div><div>                                                         } else {</div><div>                                                       
                xlog("maxcall:cannot send forced cancel - the previous dialog did not have a totag - preceeding state\n");    </div><div>                                                                       xlog("maxcall:I am in call with call-id: $ci \n");                                </div><div>                                                         }</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                             
        </span>}</div><div><br></div><div><br></div><div><br></div><div>We see this in the logs, for two quick successive calls from the same UA (same user)  so we could reach the condition</div><div>when t_cancel_callid() is called , with  $avp(saved_totag_of_previous_call) being null :</div><div><br></div><div>So this is when the the user makes the second call:</div><div><br></div><div> 0(21429) INFO: <script>: cancelling call 3e20b1db528ce041 (entry= 2776, id= 2165 ) 0(21429) DEBUG: tm [t_lookup.c:1742]: t_lookup_callid(): created comparable call_id header field: >Call-ID: 3e20b1db528ce0$</div><div><</div><div> 0(21429) DEBUG: tm [t_lookup.c:1746]: t_lookup_callid(): created comparable cseq header field: >CSeq: 20 INVITE<</div><div> 0(21429) DEBUG: tm [t_lookup.c:1749]: t_lookup_callid(): just locked hash index 57175, looking for transactions there:</div><div> 0(21429) DEBUG: tm [t_lookup.c:1762]:
 t_lookup_callid(): we have a match: callid=>>Call-ID: 3e20b1db528ce041</div><div><< cseq=>>CSeq: 20<<</div><div> 0(21429) DEBUG: tm [t_lookup.c:1767]: t_lookup_callid(): DEBUG: t_lookup_callid: transaction found.</div><div> 0(21429) DEBUG: tmx [tmx_mod.c:364]: t_cancel_callid(): Now calling cancel_uacs</div><div> 0(21429) DEBUG: tm [t_cancel.c:329]: cancel_branch(): DEBUG: cancel_branch: sending cancel...</div><div> 0(21429) ERROR: <script>: maxcall:transaction cancelled . i am in call with call-id: 2bf9efb7528ce04d  #  <- this is our custom logging</div><div> 0(21429) ERROR: <script>: the other call (previous) had call-id:  3e20b1db528ce041 </div><div><br></div><div>[...]</div><div><br></div><div>then:</div><div><br></div><div> 0(21429) DEBUG: dialog [dlg_hash.c:600]: dlg_lookup(): ref dlg 0x7f4179801d08 with 1 -> 2</div><div> 0(21429) DEBUG: dialog
 [dlg_hash.c:602]: dlg_lookup(): dialog id=9721 found on entry 2505</div><div> 0(21429) DEBUG: dialog [dlg_var.c:49]: dlg_cfg_cb(): new dialog with no trasaction after config execution</div><div> 0(21429) DEBUG: dialog [dlg_hash.c:765]: dlg_unref(): unref dlg 0x7f4179801d08 with 1 -> 1</div><div> 0(21429) DEBUG: dialog [dlg_hash.c:765]: dlg_unref(): unref dlg 0x7f4179801d08 with 1 -> 0</div><div> 0(21429) DEBUG: dialog [dlg_hash.c:765]: dlg_unref(): ref <=0 for dialog 0x7f4179801d08</div><div> 0(21429) DEBUG: dialog [dlg_hash.c:316]: destroy_dlg(): destroying dialog 0x7f4179801d08 (ref 0)</div><div> 0(21429) DEBUG: dialog [dlg_hash.c:332]: destroy_dlg(): removed timer for dlg 0x7f4179801d08 [2505:9721] with clid '2bf9efb7528ce04d' and tags '76bc4edf528ce04d' ''</div><div><br></div><div><br></div><div>What happens is that kamailio seems that it destroys the second dialog , instead of the first one. This leads to
 other inconsitency :</div><div><br></div><div>DEBUG: dialog [dlg_hash.c:664]: internal_get_dlg(): no dialog callid='2bf9efb7528ce04d' found  # <- it cannot match the ACK for the second call.</div><div><br></div><div>[...]</div><div><br></div><div> 0(21429) WARNING: dialog [dlg_handlers.c:1127]: dlg_onroute(): unable to find dialog for BYE with route param '9c9.9f52' [2505:9721]   # <- it cannot match the BYE for the second call</div><div> 0(21429) DEBUG: dialog [dlg_hash.c:664]: internal_get_dlg(): no dialog callid='2bf9efb7528ce04d' found</div><div> 0(21429) DEBUG: dialog [dlg_hash.c:695]: get_dlg(): no dialog callid='2bf9efb7528ce04d' found</div><div> 0(21429) DEBUG: dialog [dlg_handlers.c:1173]: dlg_onroute(): Callid '2bf9efb7528ce04d' not found</div><div><br></div><div>[...]</div><div><br></div><div> 1(21430) INFO: <script>: event_route[local-request]: call-id=3e20b1db528ce041 from=15909901
 to=+33630815276 : local_route (method= BYE) :: dlg flag: 1 1(21430) DEBUG: pv [pv_trans.c:315]: tr_eval_string(): i=0 j=1</div><div> 0(21429) WARNING: dialog [dlg_req_within.c:177]: bye_reply_cb(): inconsitent dlg timer data on dlg 0x7f41797e7048 [2776:2165] with clid '3e20b1db528ce041' and tags '522612bb528ce041' 'as1b2c7ace'</div><div> 0(21429) DEBUG: dialog [dlg_hash.c:332]: destroy_dlg(): removed timer for dlg 0x7f41797e7048 [2776:2165] with clid '3e20b1db528ce041' and tags '522612bb528ce041' 'as1b2c7ace'</div><div><br></div><div><br></div><div>It it also mixing the timeout of the first dialog with the one of the second. If we put a default timeout of 15 seconds for all calls </div><div>and we cancel the first call,kamailio will generate a BYEs in event_route[tm:local-request] after 15 seconds after the call other call was answered, </div><div>but with the call-id of the first call - it is mixing dialogs as we can see with
 kamctl.</div><div><br></div><div>We suspect that t_cancel_callid() is not destroying the proper dialog at the right time.  We use dlg_manage() on every INVITE.</div><div><br></div><div>It is the same behaviour with kamailio 4.0.2 and kamailio 4.0.3 .</div><div><br></div><div>Any hints / ideas about this problem ? Is the problem in the dialog module, or t_cancel_callid() is doing something wrong ?</div><div><br></div><div><br></div><div>Thank you.</div><div><br></div><div>Regards,</div><div><span></span></div><div>Dragos</div><div><br></div><div class="yahoo_quoted" style="display: block;"> <br> <br> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 10pt;"> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Wednesday, November 20, 2013 10:57 PM, Daniel-Constantin
 Mierla <miconda@gmail.com> wrote:<br> </font> </div>  <div class="y_msg_container"><div id="yiv0452215972"><div>
    Hello,<br clear="none">
    <br clear="none">
    are you dropping replies? I don't see the 'SIP/2.0 487 Request
    Terminated' being sent to caller, it looks ok and has two Via
    headers.<br clear="none">
    <br clear="none">
    Cheers,<br clear="none">
    Daniel<br clear="none">
    <br clear="none">
    <div class="yiv0452215972moz-cite-prefix">On 11/20/13 4:06 PM, Guillaume Bour
      wrote:<br clear="none">
    </div>
    <blockquote type="cite">
      </blockquote></div><div><div class="yiv0452215972moz-cite-prefix">On 20/11/2013 12:01,
        Daniel-Constantin Mierla wrote:<br clear="none">
      </div>
      <blockquote type="cite">
        </blockquote></div><div>
        Hello,<br clear="none">
        <br clear="none">
        <div class="yiv0452215972moz-cite-prefix">On 11/20/13 11:50 AM, Guillaume
          Bour wrote:<br clear="none">
        </div>
        <blockquote type="cite">
          </blockquote></div><div>
          Hi All<br clear="none">
          <br clear="none">
          We wan't to prevent our users to make more than one call at
          time, so we choose to disconnect the previous call.<br clear="none">
          When the previous call is established, we use dlg_bye(), and
          its ok.<br clear="none">
          But when it is in early state, we use t_cancel_callid() to
          cancel its INVITE transaction.<br clear="none">
          <br clear="none">
          We face 2 issues:<br clear="none">
              1) we use local-request event route to account calls on
          timeout. Sometimes this route is called for the cancelled call
          (after default timeout of 1 hour)<br clear="none">
        
        <br clear="none">
        what is in the local-request in this case? Is it a BYE?<br clear="none">
        <br clear="none">
        <blockquote type="cite">
              2) t_cancel_callid() cancel previous call, but also <u>make

            current dialog disappear</u>: call is still ongoing and we
          can answer and talk to each other, but the dialog does not
          appear in 'kamctl stats dialog' and 'kamctl mi dlg_list'
          commands<br clear="none">
          <br clear="none">
          Is there a known limitation, or do we misuse t_cancel_callid()
          ?<br clear="none">
        </blockquote>
        Can you send the log with debug=3 in kamailio.cfg? It will help
        to see what happens. Otherwise, if the call id is different for
        current dialog, it should not happen. The ngrep output in this
        situation (for both first and second invite) will help.<br clear="none">
        <br clear="none">
        Cheers,<br clear="none">
        Daniel<br clear="none">
        <br clear="none">
      
      <br clear="none">
      <br clear="none">
      Hi Daniel,<br clear="none">
      <br clear="none">
      local-request is triggered by a BYE<br clear="none">
      I have attached sample log and trace<br clear="none">
      <br clear="none">
      There is some kind of dialogs mixing. Here is the 1st call dialog
      as reported by "kamctl mi dlg_list" <u>before and after</u> the
      2d call is answered:<br clear="none">
      <br clear="none">
      # kamctl mi dlg_list<br clear="none">
      dialog::  hash=2790:3231<br clear="none">
              state:: 2<br clear="none">
              ref_count:: 1<br clear="none">
              timestart:: 0<br clear="none">
              timeout:: 0<br clear="none">
              callid:: GoXhk8GfkIEEqFyFNcySEjSOOpVKg4Uq<br clear="none">
              from_uri:: <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-abbreviated" ymailto="mailto:sip:15909901@staging.voip" target="_blank" href="mailto:sip:15909901@staging.voip">sip:15909901@staging.voip</a><br clear="none">
              from_tag:: swYh88AkicGbSHpK.D1z7uo3EX9Q-.AZ<br clear="none">
              caller_contact:: <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-abbreviated" ymailto="mailto:sip:37984520-gch2kindtioq8@10.0.1.10:5060;transport=udp" target="_blank" href="mailto:sip:37984520-gch2kindtioq8@10.0.1.10:5060;transport=udp">sip:37984520-gch2kindtioq8@10.0.1.10:5060;transport=udp</a><br clear="none">
              caller_cseq:: 24899<br clear="none">
              caller_route_set::<br clear="none">
              caller_bind_addr:: <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-freetext" href="">udp:10.0.1.10:5060</a><br clear="none">
              callee_bind_addr::<br clear="none">
              to_uri:: <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-abbreviated" ymailto="mailto:sip:+3360000011@staging.voip" target="_blank" href="mailto:sip:+3360000011@staging.voip">sip:+3360000011@staging.voip</a><br clear="none">
              to_tag::<br clear="none">
              callee_contact::<br clear="none">
              callee_cseq::<br clear="none">
              callee_route_set::<br clear="none">
      <br clear="none">
      # kamctl mi dlg_list<br clear="none">
      dialog::  hash=2790:3231<br clear="none">
              state:: 3<br clear="none">
              ref_count:: 2<br clear="none">
              timestart:: 1384952191<br clear="none">
              timeout:: 20242152<br clear="none">
              callid:: GoXhk8GfkIEEqFyFNcySEjSOOpVKg4Uq<br clear="none">
              from_uri:: <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-abbreviated" ymailto="mailto:sip:15909901@staging.voip" target="_blank" href="mailto:sip:15909901@staging.voip">sip:15909901@staging.voip</a><br clear="none">
              from_tag:: swYh88AkicGbSHpK.D1z7uo3EX9Q-.AZ<br clear="none">
              caller_contact:: <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-abbreviated" ymailto="mailto:sip:37984520-gch2kindtioq8@10.0.1.20:5060;transport=udp" target="_blank" href="mailto:sip:37984520-gch2kindtioq8@10.0.1.20:5060;transport=udp">sip:37984520-gch2kindtioq8@10.0.1.20:5060;transport=udp</a><br clear="none">
              caller_cseq:: 24899<br clear="none">
              caller_route_set::<br clear="none">
              caller_bind_addr:: <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-freetext" href="">udp:10.0.1.10:5060</a><br clear="none">
              callee_bind_addr:: <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-freetext" href="">udp:10.0.1.10:5060</a><br clear="none">
              to_uri:: <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-abbreviated" ymailto="mailto:sip:+3360000011@staging.voip" target="_blank" href="mailto:sip:+3360000011@staging.voip">sip:+3360000011@staging.voip</a><br clear="none">
              to_tag:: as6c8b935a<br clear="none">
              callee_contact:: <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-abbreviated" ymailto="mailto:sip:+3360000022@10.0.1.11:5060" target="_blank" href="mailto:sip:+3360000022@10.0.1.11:5060">sip:+3360000022@10.0.1.11:5060</a><br clear="none">
              callee_cseq::<br clear="none">
              callee_route_set::<br clear="none">
      <br clear="none">
      <br clear="none">
      <br clear="none">
      <br clear="none">
      <fieldset class="yiv0452215972mimeAttachmentHeader"></fieldset>
      <br clear="none">
      <pre>_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
<a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-abbreviated" ymailto="mailto:sr-users@lists.sip-router.org" target="_blank" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a>
<a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-freetext" target="_blank" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    
    <div class="yiv0452215972yqt7080257816" id="yiv0452215972yqtfd53097"><br clear="none">
    </div><pre class="yiv0452215972moz-signature"><div class="yiv0452215972yqt7080257816" id="yiv0452215972yqtfd61078">-- 
Daniel-Constantin Mierla - </div><a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-freetext" target="_blank" href="http://www.asipto.com/">http://www.asipto.com</a>
<a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-freetext" target="_blank" href="http://twitter.com/#!/miconda">http://twitter.com/#!/miconda</a> - <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-freetext" target="_blank" href="http://www.linkedin.com/in/miconda">http://www.linkedin.com/in/miconda</a>
Kamailio Advanced Trainings - Berlin, Nov 25-28
  - more details about Kamailio trainings at <a rel="nofollow" shape="rect" class="yiv0452215972moz-txt-link-freetext" target="_blank" href="http://www.asipto.com/">http://www.asipto.com</a><div class="yiv0452215972yqt7080257816" id="yiv0452215972yqtfd44396"> -
</div></pre><div class="yiv0452215972yqt7080257816" id="yiv0452215972yqtfd99677">
  </div></div></div><br><div class="yqt7080257816" id="yqtfd47557">_______________________________________________<br clear="none">SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list<br clear="none"><a shape="rect" ymailto="mailto:sr-users@lists.sip-router.org" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a><br clear="none"><a shape="rect" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a><br clear="none"></div><br><br></div>  </div> </div>  </div> </div></body></html>