<html>
  <head>
    <meta content="text/html; charset=gb18030" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix"><tt>Hi,<br>
        OK, that's good. But not enough - as Liviu mentioned in a
        separate email, the test and set you do (check the number of
        dialogs and create a new dialog) is not an atomic operation,
        considering the fact that opensips is doing multi-processing.
        You should protect that test&amp;set operation with a lock, to make
        it atomic. see:<br>
           
        <a class="moz-txt-link-freetext" href="http://www.opensips.org/html/docs/modules/1.11.x/cfgutils.html#id294109">http://www.opensips.org/html/docs/modules/1.11.x/cfgutils.html#id294109</a><br>
        <br>
        Regards,<br>
      </tt>
      <pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a class="moz-txt-link-freetext" href="http://www.opensips-solutions.com">http://www.opensips-solutions.com</a></pre>
      On 15.07.2014 14:29, jing wrote:<br>
    </div>
    <blockquote cite="mid:tencent_410D62904DFC7684586A9A5E@qq.com"
      type="cite">
      <div>
        <div>hi,Bogdan<br>
          Thanks for your help.</div>
        <div>I changed the script as fllow. Then when I start the second
          call ,it send 503.</div>
        <div>
          <div>if (is_method("INVITE")) {<br>
            xlog("active dialog is $stat(active_dialogs)");</div>
          <div>if ($DLG_count&gt;=1){</div>
          <div> xlog("we have more than 1 call(s) - currently
            $stat(active_dialogs) \n");<br>
            sl_send_reply("503", "Service Unavailable");<br>
            exit;<br>
            }<br>
            # create dialog with timeout<br>
            if ( !create_dialog("B") ) {<br>
            send_reply("500","Internal Server Error");<br>
            exit;<br>
            }</div>
          <div>setflag(ACC_DO); # do accounting<br>
            }</div>
          <div> </div>
          <div>Thanks,<br>
            Regards,<br>
            jing<br>
            <br>
          </div>
        </div>
      </div>
      <div><br>
      </div>
      <div><br>
      </div>
      <div style="font-size: 12px;font-family: Arial Narrow;padding:2px
        0 2px 0;">------------------ 原始邮件 ------------------</div>
      <div style="font-size: 12px;background:#efefef;padding:8px;">
        <div><b>发件人:</b> "Bogdan-Andrei
          Iancu"<a class="moz-txt-link-rfc2396E" href="mailto:bogdan@opensips.org">&lt;bogdan@opensips.org&gt;</a>; </div>
        <div><b>发送时间:</b> 2014年7月15日(星期二) 下午5:35</div>
        <div><b>收件人:</b> "jing "<a class="moz-txt-link-rfc2396E" href="mailto:605507247@qq.com">&lt;605507247@qq.com&gt;</a>;
          "users"<a class="moz-txt-link-rfc2396E" href="mailto:users@lists.opensips.org">&lt;users@lists.opensips.org&gt;</a>; </div>
        <div><b>主题:</b> Re: 回复: 回复: [OpenSIPS-Users] 回复: 回复: Dialog
          Concurrency Control Issue.</div>
      </div>
      <div><br>
      </div>
      <div class="moz-cite-prefix"><tt>Place a xlog message inside the
          IF statement, to see if you ever get there :<br>
          <br>
        </tt><br>
                        if ($stat(active_dialogs)&gt;=1){<br>
                        xlog("we have more than 1 call(s) - currently
        $stat(active_dialogs) \n");<br>
                        sl_send_reply("503", "Service Unavailable");<br>
                   <b>    exit;</b><br>
                        }
        <pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.opensips-solutions.com" target="_blank">http://www.opensips-solutions.com</a></pre>
        On 15.07.2014 12:28, jing wrote:<br>
      </div>
      <blockquote cite="mid:tencent_0F2B992D67CEA29059A3FC30@qq.com"
        type="cite">
        <div>hi,Bogdan<br>
        </div>
        <div>I have tried ,  but it is no change to have exit.</div>
        <div>regards,</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div style="PADDING-BOTTOM: 2px; PADDING-LEFT: 0px;
          PADDING-RIGHT: 0px; FONT-FAMILY: Arial Narrow; FONT-SIZE:
          12px; PADDING-TOP: 2px">------------------ 原始邮
          件 ------------------</div>
        <div style="PADDING-BOTTOM: 8px; PADDING-LEFT: 8px;
          PADDING-RIGHT: 8px; BACKGROUND: #efefef; FONT-SIZE: 12px;
          PADDING-TOP: 8px">
          <div><b>发件人:</b> "Bogdan-Andrei Iancu"<a
              moz-do-not-send="true" class="moz-txt-link-rfc2396E"
              href="mailto:bogdan@opensips.org" target="_blank">&lt;bogdan@opensips.org&gt;</a>;
          </div>
          <div><b>发送时间:</b> 2014年7月15日(星期二) 下午5:26</div>
          <div><b>收件人:</b> "jing "<a moz-do-not-send="true"
              class="moz-txt-link-rfc2396E"
              href="mailto:605507247@qq.com" target="_blank">&lt;605507247@qq.com&gt;</a>;
            "users"<a moz-do-not-send="true"
              class="moz-txt-link-rfc2396E"
              href="mailto:users@lists.opensips.org" target="_blank">&lt;users@lists.opensips.org&gt;</a>;
          </div>
          <div><b>主题:</b> Re: 回复: [OpenSIPS-Users] 回复: 回复: Dialog
            Concurrency Control Issue.</div>
        </div>
        <div><br>
        </div>
        <div class="moz-cite-prefix"><tt>Because you need to have an
            "exit;" after the sl_send_reply():<br>
            <br>
          </tt><br>
                          if ($stat(active_dialogs)&gt;=1){<br>
                          sl_send_reply("503", "Service Unavailable");<br>
                     <b>    exit;</b><br>
                          }<br>
          <br>
          Otherwise the script execution will continue.<br>
          <br>
          Regards,<br>
          <pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a class="moz-txt-link-freetext" href="http://www.opensips-solutions.com" target="_blank" moz-do-not-send="true">http://www.opensips-solutions.com</a></pre>
          On 15.07.2014 12:19, jing wrote:<br>
        </div>
        <blockquote cite="mid:tencent_48ED3AD33206F1B3771E1C3D@qq.com"
          type="cite">
          <div>hi,Bogdan.</div>
          <div> </div>
          <div>I just want to limit the total number of active dialog.
            And now I have 2 questions .</div>
          <div> </div>
          <div>I changed the script like this:</div>
          <div> </div>
          <div>if (is_method("INVITE")) {<br>
                            xlog("active dialog is
            $stat(active_dialogs)");<br>
                            xlog("dlgcount is $DLG_count");<br>
                            if ($stat(active_dialogs)&gt;=1){<br>
                            sl_send_reply("503", "Service Unavailable");<br>
            <br>
                            }<br>
                            # create dialog with timeout<br>
                            if ( !create_dialog("B") ) {<br>
                                    send_reply("500","Internal Server
            Error");<br>
                                    exit;<br>
                            }</div>
          <div>                setflag(ACC_DO); # do accounting<br>
                    }<br>
          </div>
          <div>Then I started 3 dialog, they were all successful , but
            no 503 sent. The log showed:</div>
          <div>
            <div>active dialog is 2<br>
              dlgcount is 2</div>
          </div>
          <div> </div>
          <div>I used opensipsctl fifo command to show the dialog
            statistics, it showed </div>
          <div>dialog:active_dialogs = 3.</div>
          <div>1.what is wrong in my script ?</div>
          <div>2. How to end the dialogs which have been active long
            time ,but have no response.</div>
          <div> </div>
          <div>Or is there other way to limit the total number of active
            dialog?</div>
          <div> </div>
          <div>I am a newbie to opensips,  would you please tell me more
            detailed advice?</div>
          <div>Very thanks!</div>
          <div>kind regards</div>
          <div> </div>
          <div><br>
          </div>
          <div><br>
          </div>
          <div style="PADDING-BOTTOM: 2px; PADDING-LEFT: 0px;
            PADDING-RIGHT: 0px; FONT-FAMILY: Arial Narrow; FONT-SIZE:
            12px; PADDING-TOP: 2px">------------------ 原始邮
            件 ------------------</div>
          <div style="PADDING-BOTTOM: 8px; PADDING-LEFT: 8px;
            PADDING-RIGHT: 8px; BACKGROUND: #efefef; FONT-SIZE: 12px;
            PADDING-TOP: 8px">
            <div><b>发件人:</b> "Bogdan-Andrei Iancu"<a
                class="moz-txt-link-rfc2396E"
                href="mailto:bogdan@opensips.org" target="_blank"
                moz-do-not-send="true">&lt;bogdan@opensips.org&gt;</a>;
            </div>
            <div><b>发送时间:</b> 2014年7月15日(星期二) 下午4:43</div>
            <div><b>收件人:</b> "users"<a class="moz-txt-link-rfc2396E"
                href="mailto:users@lists.opensips.org" target="_blank"
                moz-do-not-send="true">&lt;users@lists.opensips.org&gt;</a>;
              "jing "<a class="moz-txt-link-rfc2396E"
                href="mailto:605507247@qq.com" target="_blank"
                moz-do-not-send="true">&lt;605507247@qq.com&gt;</a>; </div>
            <div><b>主题:</b> Re: [OpenSIPS-Users] 回复: 回复: Dialog
              Concurrency Control Issue.</div>
          </div>
          <div><br>
          </div>
          <div class="moz-cite-prefix"><tt>Hi,<br>
              <br>
              I see you added the missing "exit" after the
              sl_send_reply() and you do create the dialog for each
              INVITE (hopefully only for the initial ones :) ). <br>
              <br>
              What seems to be the exact problem now ?<br>
              <br>
              Regards,<br>
            </tt>
            <pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a class="moz-txt-link-freetext" href="http://www.opensips-solutions.com" target="_blank" moz-do-not-send="true">http://www.opensips-solutions.com</a></pre>
            On 15.07.2014 05:21, jing wrote:<br>
          </div>
          <blockquote cite="mid:tencent_6BBDD6C6338F7B911A4403D3@qq.com"
            type="cite">
            <div>hi,Schneur.</div>
            <div>Thanks for your advice.</div>
            <div>But I did put the check before  create_dialog("B")  in
              the original oprnsips.cfg:</div>
            <div> </div>
            <div>if (is_method("INVITE")) {<br>
                              xlog("active dialog is
              $stat(active_dialogs)");</div>
            <div>                if ($stat(active_dialogs)&gt;=1){<br>
                              sl_send_reply("503", "Service
              Unavailable");<br>
                              exit;<br>
                              }<br>
                              # create dialog with timeout<br>
                              if ( !create_dialog("B") ) {<br>
                                      send_reply("500","Internal Server
              Error");<br>
                                      exit;<br>
                              }</div>
            <div>                setflag(ACC_DO); # do accounting<br>
                      }</div>
            <div> </div>
            <div>
              <div><br>
              </div>
              <div>So what is wrong in the script?</div>
              <div>And I still want to know how to judge a call is
                "active_dialogs"?</div>
              <div>Thanks a lot.</div>
              <div> </div>
              <div>regards,</div>
              <div>jing<br>
              </div>
              <div style="PADDING-BOTTOM: 2px; PADDING-LEFT: 0px;
                PADDING-RIGHT: 0px; FONT-FAMILY: Arial Narrow;
                FONT-SIZE: 12px; PADDING-TOP: 2px">------------------ 原始
                邮 件 ------------------</div>
              <div style="PADDING-BOTTOM: 8px; PADDING-LEFT: 8px;
                PADDING-RIGHT: 8px; BACKGROUND: #efefef; FONT-SIZE:
                12px; PADDING-TOP: 8px">
                <div><b>发件人:</b> "Schneur Rosenberg";<a
                    class="moz-txt-link-rfc2396E"
                    href="mailto:rosenberg11219@gmail.com"
                    target="_blank" moz-do-not-send="true">&lt;rosenberg11219@gmail.com&gt;</a>;</div>
                <div><b>发送时间:</b> 2014年7月14日(星期一) 晚上6:25</div>
                <div><b>收件人:</b> "OpenSIPS users mailling list"<a
                    class="moz-txt-link-rfc2396E"
                    href="mailto:users@lists.opensips.org"
                    target="_blank" moz-do-not-send="true">&lt;users@lists.opensips.org&gt;</a>;
                  <wbr></div>
                <div><b>主题:</b> Re: [OpenSIPS-Users]回复: Dialog
                  Concurrency Control Issue.</div>
              </div>
              <div><br>
              </div>
              <p dir="ltr">You need to do this before the
                create_dialog() call</p>
              <div class="gmail_quote">On Jul 14, 2014 10:33 AM, "jing"
                &lt;<a href="mailto:605507247@qq.com" target="_blank"
                  moz-do-not-send="true">605507247@qq.com</a>&gt; wrote:<br
                  type="attribution">
                <blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN:
                  0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
                  class="gmail_quote">
                  <div><font color="#000000">Thanks for your reply.But I
                      have another question, I used  active_dialogs </font><font
                      color="#000000"> in the cfg file as this:</font></div>
                  <div> </div>
                  <div><font color="#000000">if (is_method("INVITE")) {<br>
                                      if ($stat(active_dialogs)&gt;=1){<br>
                                      sl_send_reply("503", "Service
                      Unavailable");<br>
                                      }<br>
                    </font></div>
                  <div><font color="#000000">
                      <div><font color="#000000">But it seems not right.
                        </font></div>
                      <div><font color="#000000">I use sipp to test the
                          limit ,but when the value of active_dialogs</font><font
                          color="#000000"> aim to the number I set ,</font></div>
                      <div><font color="#000000">opensips sent 503,but 
                          the value of active_dialogs<font
                            color="#000000"> </font>sitll increase. </font></div>
                      <div><font color="#000000">So I want to know how
                          the value of this paramer come</font><font
                          color="#000000">from.</font></div>
                      <div><font color="#000000">Or is there something
                          wrong in my cfg document?</font></div>
                      <div> </div>
                      <div>regards,</div>
                      <div>Jing</div>
                    </font></div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                  <div style="PADDING-BOTTOM: 2px; PADDING-LEFT: 0px;
                    PADDING-RIGHT: 0px; FONT-FAMILY: Arial Narrow;
                    FONT-SIZE: 12px; PADDING-TOP: 2px">------------------ 原
                    始 邮 件 ------------------</div>
                  <div style="PADDING-BOTTOM: 8px; PADDING-LEFT: 8px;
                    PADDING-RIGHT: 8px; BACKGROUND: #efefef; FONT-SIZE:
                    12px; PADDING-TOP: 8px">
                    <div><b>发件人:</b> "Schneur Rosenberg [via OpenSIPS
                      (Open SIP Server)]"&lt;<a
                        href="http://user/SendEmail.jtp?type=node&amp;node=7592371&amp;i=0"
                        rel="nofollow" target="_blank"
                        moz-do-not-send="true" link="external">[hidden
                        email]</a>&gt;; </div>
                    <div><b>发送时间:</b> 2014年7月14日(星期一) 下午2:08</div>
                    <div><b>收件人:</b> "jing "&lt;<a
                        href="http://user/SendEmail.jtp?type=node&amp;node=7592371&amp;i=1"
                        rel="nofollow" target="_blank"
                        moz-do-not-send="true" link="external">[hidden
                        email]</a>&gt;; </div>
                    <div><b>主题:</b> Re: Dialog Concurrency Control
                      Issue.</div>
                  </div>
                  <div><br>
                  </div>
                  <p dir="ltr">Very simple, before creating a new dialog
                    check how many open dialogs exist.</p>
                  <div class="gmail_quote">On Jul 14, 2014 9:05 AM,
                    "jing" &lt;<a
                      href="http://user/SendEmail.jtp?type=node&amp;node=7592369&amp;i=0"
                      rel="nofollow" target="_blank"
                      moz-do-not-send="true" link="external">[hidden
                      email]</a>&gt; wrote:<br type="attribution">
                    <blockquote style="BORDER-LEFT: #cccccc 2px solid;
                      PADDING-BOTTOM: 0px; PADDING-LEFT: 1em;
                      PADDING-RIGHT: 1em; PADDING-TOP: 0px"
                      class="gmail_quote">hi,Bogdan<br>
                      <br>
                      <br>
                       I want to limit the total number of active
                      dialogs ,what should I do ?<br>
                      <br>
                      I found there are many questions about "Concurrent
                      calls limitation " based<br>
                      on per user, it's not what I need.<br>
                      <br>
                      I appreciate your advice very much,  more detailed
                      the better.<br>
                      <br>
                      Thanks,<br>
                      Regards,<br>
                      jing<br>
                      <br>
                      <br>
                      <br>
                      --<br>
                      View this message in context: <a
href="http://opensips-open-sip-server.1449251.n2.nabble.com/Dialog-Concurrency-Control-Issue-tp6172931p7592368.html"
                        rel="nofollow" target="_blank"
                        moz-do-not-send="true" link="external">http://opensips-open-sip-server.1449251.n2.nabble.com/Dialog-Concurrency-Control-Issue-tp6172931p7592368.html</a><br>
                      Sent from the OpenSIPS - Users mailing list
                      archive at Nabble.com.<br>
                      <br>
                      _______________________________________________<br>
                      Users mailing list<br>
                      <a
                        href="http://user/SendEmail.jtp?type=node&amp;node=7592369&amp;i=1"
                        rel="nofollow" target="_blank"
                        moz-do-not-send="true" link="external">[hidden
                        email]</a><br>
                      <a
                        href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users"
                        rel="nofollow" target="_blank"
                        moz-do-not-send="true" link="external">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
                    </blockquote>
                  </div>
                  <br>
                  _______________________________________________ <br>
                  Users mailing list <br>
                  <a
                    href="http://user/SendEmail.jtp?type=node&amp;node=7592369&amp;i=2"
                    rel="nofollow" target="_blank"
                    moz-do-not-send="true" link="external">[hidden
                    email]</a> <br>
                  <a
                    href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users"
                    rel="nofollow" target="_blank"
                    moz-do-not-send="true" link="external">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
                  <br>
                  <br>
                  <hr color="#cccccc" noshade="noshade" size="1">
                  <div style="FONT: 12px tahoma, geneva, helvetica,
                    arial, sans-serif; COLOR: #444">
                    <div style="FONT-WEIGHT: bold">If you reply to this
                      email, your message will be added to the
                      discussion below:</div>
                    <a
href="http://opensips-open-sip-server.1449251.n2.nabble.com/Dialog-Concurrency-Control-Issue-tp6172931p7592369.html"
                      rel="nofollow" target="_blank"
                      moz-do-not-send="true" link="external">http://opensips-open-sip-server.1449251.n2.nabble.com/Dialog-Concurrency-Control-Issue-tp6172931p7592369.html</a>
                  </div>
                  <div style="MARGIN-TOP: 0.4em; FONT: 11px/1.5em
                    tahoma, geneva, helvetica, arial, sans-serif; COLOR:
                    #666">To unsubscribe from Dialog Concurrency Control
                    Issue., <a rel="nofollow" moz-do-not-send="true"
                      link="external">click here</a>.<br>
                    <a style="FONT: 9px serif"
href="http://opensips-open-sip-server.1449251.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&amp;id=instant_html%21nabble%3Aemail.naml&amp;base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&amp;breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml"
                      rel="nofollow" target="_blank"
                      moz-do-not-send="true" link="external">NAML</a> </div>
                  <br>
                  <hr align="left" width="300">
                  View this message in context: <a
href="http://opensips-open-sip-server.1449251.n2.nabble.com/Dialog-Concurrency-Control-Issue-tp7592371.html"
                    target="_blank" moz-do-not-send="true">回复: Dialog
                    Concurrency Control Issue.</a><br>
                  Sent from the <a
href="http://opensips-open-sip-server.1449251.n2.nabble.com/OpenSIPS-Users-f1449235.html"
                    target="_blank" moz-do-not-send="true">OpenSIPS -
                    Users mailing list archive</a> at Nabble.com.<br>
                  <br>
                  _______________________________________________<br>
                  Users mailing list<br>
                  <a href="mailto:Users@lists.opensips.org"
                    target="_blank" moz-do-not-send="true">Users@lists.opensips.org</a><br>
                  <a
                    href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users"
                    target="_blank" moz-do-not-send="true">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a><br>
                  <br>
                </blockquote>
              </div>
            </div>
            <br>
            <fieldset class="mimeAttachmentHeader"></fieldset>
            <br>
            <pre wrap="">_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org" target="_blank" moz-do-not-send="true">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank" moz-do-not-send="true">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
</pre>
          </blockquote>
          <br>
        </blockquote>
        <br>
      </blockquote>
      <br>
    </blockquote>
    <br>
  </body>
</html>