<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello,</p>
    <p>you have to look at your routing script and see if it is missing
      some return or exit to stop processing when the reply is sent out.</p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div class="moz-cite-prefix">On 26.01.22 18:22, Lewis Hutchinson
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CWXP265MB251774B6028CA9B039EB788CC5209@CWXP265MB2517.GBRP265.PROD.OUTLOOK.COM">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style>@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        font-size:10.0pt;
        font-family:"Courier New";}span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        mso-fareast-language:EN-US;}span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}div.WordSection1
        {page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal">Hi Daniel<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <div>
          <p>Many thanks, this is in the early stages and to undergo
            extensive testing which I suspect will see a lot efforts to
            improve and refine. This was previously written in native
            kamailio but for other reasons moved to python. Any feedback
            always welcome<br>
            <br>
            “looks like after sending the response execution continues
            somewhere else hitting t_check_trans() which detect the
            transaction exists and re-sends the last last reply (as it
            is supposed to behave).” can you think why this only occur
            on a re SUBSCRIBE<span
              style="font-size:10.5pt;font-family:"Segoe
              UI",sans-serif;color:#242424;background:white"><o:p></o:p></span></p>
          <p><span style="font-size:10.5pt;font-family:"Segoe
              UI",sans-serif;color:#242424;background:white">There
              is no intelligence in the reply needed just an accurate
              response from the API transformed into a reply 200, 500
              etc etc<o:p></o:p></span></p>
          <p><br>
            <br>
            <b><span style="font-size:12.0pt;color:black">Lewis </span></b><o:p></o:p></p>
        </div>
        <p class="MsoNormal"><o:p> </o:p></p>
        <div>
          <div style="border:none;border-top:solid #E1E1E1
            1.0pt;padding:3.0pt 0cm 0cm 0cm">
            <p class="MsoNormal"><b><span
                  style="mso-fareast-language:EN-GB" lang="EN-US">From:</span></b><span
                style="mso-fareast-language:EN-GB" lang="EN-US">
                Daniel-Constantin Mierla <a class="moz-txt-link-rfc2396E" href="mailto:miconda@gmail.com"><miconda@gmail.com></a>
                <br>
                <b>Sent:</b> 26 January 2022 16:37<br>
                <b>To:</b> Kamailio (SER) - Users Mailing List
                <a class="moz-txt-link-rfc2396E" href="mailto:sr-users@lists.kamailio.org"><sr-users@lists.kamailio.org></a>; Lewis Hutchinson
                <a class="moz-txt-link-rfc2396E" href="mailto:lewis.hutchinson@missionlabs.co.uk"><lewis.hutchinson@missionlabs.co.uk></a><br>
                <b>Subject:</b> Re: [SR-Users] 200 OK re transmission
                only on re-SUBSCRIBE<o:p></o:p></span></p>
          </div>
        </div>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p>Hello,<o:p></o:p></p>
        <p>looks like after sending the response execution continues
          somewhere else hitting t_check_trans() which detect the
          transaction exists and re-sends the last last reply (as it is
          supposed to behave).<o:p></o:p></p>
        <p>Be also careful with async processing in python, I am not
          familiar with it at all, just be aware that kamailio has a
          multi-process design and uses per-process global variables. if
          you do multi-threading async processing in python, be sure you
          ensure consistency of globals and avoid races to read+change
          them.<o:p></o:p></p>
        <p>Cheers,<br>
          Daniel<o:p></o:p></p>
        <div>
          <p class="MsoNormal">On 26.01.22 16:53, Lewis Hutchinson
            wrote:<o:p></o:p></p>
        </div>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <p class="MsoNormal">First of all I should start by saying
            this is my first post so go easy on me!! : ) and thank for
            everyone’s efforts to share knowledge it has been invaluable
            for my kamailio learning.<br>
            <br>
            <u>Build Details</u><br>
            <br>
            Version: kamailio 5.5.3 (x86_64/linux)<br>
            Kamailio kemi python <br>
            <br>
            <u>Scenario</u><br>
            <br>
            Relevant config<br>
            <br>
            def ksr_route_api_query(self, msg):<o:p></o:p></p>
          <p class="MsoNormal">        KSR.log("info", "SUBSCRIBE API
            Query Starts")<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">        # Create new Transaction<o:p></o:p></p>
          <p class="MsoNormal">        KSR.tm.t_newtran()<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">        async def main():<o:p></o:p></p>
          <p class="MsoNormal">            url = '<a
href="https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapi.hidingtheurl.com%2Fsubscribe&data=04%7C01%7Clewis.hutchinson%40missionlabs.co.uk%7Cdd21c3bd426b483f046908d9e0ea0e56%7C97c26f550a7a4661bd8f7b43b50d3f2b%7C0%7C0%7C637788119843865974%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=RUXou2G%2F5kC2rT2VKu%2BJ3YQKvimpUxe4HsyMjfqXAUk%3D&reserved=0"
              moz-do-not-send="true">https://api.hidingtheurl.com/subscribe</a>'<o:p></o:p></p>
          <p class="MsoNormal">            payload = {<o:p></o:p></p>
          <p class="MsoNormal">                "ruri":
            KSR.pv.get("$ru"),<o:p></o:p></p>
          <p class="MsoNormal">                "from":
            KSR.pv.get("$fu"),<o:p></o:p></p>
          <p class="MsoNormal">                "from_tag":
            KSR.pv.gete("$ft"),<o:p></o:p></p>
          <p class="MsoNormal">                "to": KSR.pv.get("$tu"),<o:p></o:p></p>
          <p class="MsoNormal">                "callid":
            KSR.pv.get("$ci"),<o:p></o:p></p>
          <p class="MsoNormal">                "cseq":
            KSR.pv.get("$cs"),<o:p></o:p></p>
          <p class="MsoNormal">                "contact":
            KSR.pv.gete("$ct"),<o:p></o:p></p>
          <p class="MsoNormal">                "supported":
            KSR.pv.get("$hdr(Supported)"),<o:p></o:p></p>
          <p class="MsoNormal">                "event":
            KSR.pv.get("$hdr(Event)"),<o:p></o:p></p>
          <p class="MsoNormal">                "expires":
            KSR.pv.get("$hdr(Expires)"),<o:p></o:p></p>
          <p class="MsoNormal">                "diversion":
            KSR.pv.get("$di"),<o:p></o:p></p>
          <p class="MsoNormal">                "body": KSR.pv.get("$rb")<o:p></o:p></p>
          <p class="MsoNormal">                }<o:p></o:p></p>
          <p class="MsoNormal">            async with
            aiohttp.ClientSession() as session:<o:p></o:p></p>
          <p class="MsoNormal">                async with
            session.post(url, json=payload) as response:<o:p></o:p></p>
          <p class="MsoNormal">                    if response.status ==
            0:<o:p></o:p></p>
          <p class="MsoNormal">                       
            KSR.xlog.xinfo(f"SUB Manager Timeout: {response.status}")<o:p></o:p></p>
          <p class="MsoNormal">                       
            KSR.tm.t_reply(408, "SUB Manager Timeout")<o:p></o:p></p>
          <p class="MsoNormal">                    elif response.status
            >= 500:<o:p></o:p></p>
          <p class="MsoNormal">                       
            KSR.xlog.xinfo(f"SUB Manager Down: {response.status}")<o:p></o:p></p>
          <p class="MsoNormal">                       
            KSR.tm.t_reply(500, "SUB Manager Down")<o:p></o:p></p>
          <p class="MsoNormal">                    elif response.status
            >= 400:<o:p></o:p></p>
          <p class="MsoNormal">                       
            KSR.xlog.xinfo(f"SUB Manager Error: {response.status}")<o:p></o:p></p>
          <p class="MsoNormal">                       
            KSR.tm.t_reply(400, "SUB Manager Error")<o:p></o:p></p>
          <p class="MsoNormal">                    else:<o:p></o:p></p>
          <p class="MsoNormal">                        if
            response.status == 200:<o:p></o:p></p>
          <p class="MsoNormal">                           
            KSR.xlog.xinfo(f"SUB Manager Success: {response.status}")<o:p></o:p></p>
          <p class="MsoNormal">                           
            KSR.tm.t_reply(200, "OK")<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">        KSR.log("info", "SUBSCRIBE API
            Query Ends")<o:p></o:p></p>
          <p class="MsoNormal">        asyncio.run(main())<o:p></o:p></p>
          <p class="MsoNormal">        # API Query Ends<br>
            <br>
            <u>Scenario</u><br>
            <br>
            <br>
            <o:p></o:p></p>
          <p class="MsoNormal">Initial SUBSCRIBE >>> hits
            Kamailio >>> send payload in JSON to API get
            receive 200OK response from API and send a 200OK on to
            Device
            <o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">SUBSCRIBE --------><o:p></o:p></p>
          <p class="MsoNormal"><------------ 200 OK <o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">After Subscription Expiry<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">re-SUBSCRIBE >>> hits Kamailio
            >>> send payload in JSON to API get 200OK response
            from API and send a 200OK on to Device but also another
            200OK a fraction of a second later...<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">SUBSCRIBE --------><o:p></o:p></p>
          <p class="MsoNormal"><------------ 200 OK <o:p></o:p></p>
          <p class="MsoNormal"><<<--------- 200 OK <o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal"><br>
            This happens for all following re-SUBSCRIBE's<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">The 200 OK are identical, and it is a re
            transmission, but I can’t work out why..<br>
            <br>
            Relevant DEBUG is below<br>
            <br>
            Jan 26 12:31:17 ip-172-20-46-39 kamailio[11234]: INFO:
            <script>: SUB Manager Success: 200<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: app_python3 [apy_kemi.c:232]:
            sr_apy_kemi_exec_func_ex(): execution of method: t_reply<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: app_python3 [apy_kemi.c:287]:
            sr_apy_kemi_exec_func_ex(): params[2] for: t_reply are
            int-str: [200] [OK]<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: tm [t_lookup.c:1034]: t_check_msg():
            msg (0x7eff0cd4e828) id=2/11234 global id=2/11234 T
            start=0x7eff0918d7d8<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: tm [t_lookup.c:1108]: t_check_msg():
            T (0x7eff0918d7d8) already found for msg (0x7eff0cd4e828)!<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: <core>
            [core/msg_translator.c:162]: check_via_address():
            (80.111.111.111, 80.111.111.111, 0)<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: tm [t_reply.c:1763]:
            cleanup_uac_timers(): RETR/FR timers reset<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: tm [t_reply.c:637]: _reply_light():
            reply sent out - buf=0x7eff0cd50938: SIP/2.0 200
            OK#015#012Via:... shmem=0x7eff09190ca8: SIP/2.0 200
            OK#015#012Via:<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: tm [t_reply.c:648]: _reply_light():
            finished<o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: app_python3 [apy_kemi.c:232]:
            sr_apy_kemi_exec_func_ex(): execution of method:
            t_precheck_trans<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: app_python3 [apy_kemi.c:232]:
            sr_apy_kemi_exec_func_ex(): execution of method:
            t_check_trans<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: tm [t_lookup.c:1034]: t_check_msg():
            msg (0x7eff0cd4e828) id=2/11234 global id=2/11234 T
            start=0x7eff0918d7d8<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: tm [t_lookup.c:1108]: t_check_msg():
            T (0x7eff0918d7d8) already found for msg (0x7eff0cd4e828)!<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: tm [t_reply.c:1703]:
            t_retransmit_reply(): reply retransmitted.
            buf=0x7eff0cb18220: SIP/2.0 2..., shmem=0x7eff09190ca8:
            SIP/2.0 2<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: app_python3 [apy_kemi.c:112]:
            sr_kemi_config_engine_python(): execution of route type 1
            with no name returned 1<o:p></o:p></p>
          <p class="MsoNormal">Jan 26 12:31:17 ip-172-20-46-39
            kamailio[11234]: DEBUG: <core> [core/receive.c:514]:
            receive_msg(): request-route executed in: 38258 usec<br>
            <br>
            <br>
            Everything works well as is but I want to clean up this
            issue or at least understand what is causing it.<br>
            <br>
            <br>
            <br>
            <o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal"><b><span
                style="font-size:12.0pt;color:black;mso-fareast-language:EN-GB">Lewis</span></b><o:p></o:p></p>
          <p class="MsoNormal"><span style="mso-fareast-language:EN-GB"><br>
              <br>
              <o:p></o:p></span></p>
          <pre>__________________________________________________________<o:p></o:p></pre>
          <pre>Kamailio - Users Mailing List - Non Commercial Discussions<o:p></o:p></pre>
          <pre>  * <a href="mailto:sr-users@lists.kamailio.org" moz-do-not-send="true" class="moz-txt-link-freetext">sr-users@lists.kamailio.org</a><o:p></o:p></pre>
          <pre>Important: keep the mailing list in the recipients, do not reply only to the sender!<o:p></o:p></pre>
          <pre>Edit mailing list options or unsubscribe:<o:p></o:p></pre>
          <pre>  * <a href="https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.kamailio.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fsr-users&data=04%7C01%7Clewis.hutchinson%40missionlabs.co.uk%7Cdd21c3bd426b483f046908d9e0ea0e56%7C97c26f550a7a4661bd8f7b43b50d3f2b%7C0%7C0%7C637788119843875940%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=ktFWCyiPBcm1lBD%2FufKC29cRDas8w40bz%2B%2FeqlKU4ME%3D&reserved=0" moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><o:p></o:p></pre>
        </blockquote>
        <pre>-- <o:p></o:p></pre>
        <pre>Daniel-Constantin Mierla -- <a href="https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.asipto.com%2F&data=04%7C01%7Clewis.hutchinson%40missionlabs.co.uk%7Cdd21c3bd426b483f046908d9e0ea0e56%7C97c26f550a7a4661bd8f7b43b50d3f2b%7C0%7C0%7C637788119843885892%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=sWTHp6KL5rN4GUE0AE8bjcPZ%2FY15ogA3kXohl8pFPlU%3D&reserved=0" moz-do-not-send="true">www.asipto.com</a><o:p></o:p></pre>
        <pre><a href="https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.twitter.com%2Fmiconda&data=04%7C01%7Clewis.hutchinson%40missionlabs.co.uk%7Cdd21c3bd426b483f046908d9e0ea0e56%7C97c26f550a7a4661bd8f7b43b50d3f2b%7C0%7C0%7C637788119843885892%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=9aZF1fGLjKeQHQjJh6EtQoM%2FguP78pdwEmec7wRl%2FeY%3D&reserved=0" moz-do-not-send="true">www.twitter.com/miconda</a> -- <a href="https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.linkedin.com%2Fin%2Fmiconda&data=04%7C01%7Clewis.hutchinson%40missionlabs.co.uk%7Cdd21c3bd426b483f046908d9e0ea0e56%7C97c26f550a7a4661bd8f7b43b50d3f2b%7C0%7C0%7C637788119843895840%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=M6Eisb%2FqYQ%2FnBEK8zF2vbhCycOPtGT%2B6rV3coVO6Ebo%3D&reserved=0" moz-do-not-send="true">www.linkedin.com/in/miconda</a><o:p></o:p></pre>
        <pre>Kamailio Advanced Training - Online<o:p></o:p></pre>
        <pre>  Feb 21-24, 2022 (America Timezone)<o:p></o:p></pre>
        <pre>  * <a href="https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.asipto.com%2Fsw%2Fkamailio-advanced-training-online%2F&data=04%7C01%7Clewis.hutchinson%40missionlabs.co.uk%7Cdd21c3bd426b483f046908d9e0ea0e56%7C97c26f550a7a4661bd8f7b43b50d3f2b%7C0%7C0%7C637788119843905804%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=O2YyPhALtsIevNfiWMTXdK2GMaeZ91GU%2B1ebo%2BC%2Fx9E%3D&reserved=0" moz-do-not-send="true">https://www.asipto.com/sw/kamailio-advanced-training-online/</a><o:p></o:p></pre>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
  * <a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a>
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe:
  * <a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - Online
  Feb 21-24, 2022 (America Timezone)
  * <a class="moz-txt-link-freetext" href="https://www.asipto.com/sw/kamailio-advanced-training-online/">https://www.asipto.com/sw/kamailio-advanced-training-online/</a></pre>
  </body>
</html>