<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@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;}
/* Style Definitions */
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;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        font-size:10.0pt;
        font-family:"Courier New",serif;
        mso-fareast-language:EN-GB;}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:"Calibri",sans-serif;}
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.EmailStyle24
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.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]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Thanks for everyone’s help on this, it turns out it was something as simple as a missing > 0 in the code which caused the below and sometimes resulted in noticeable delay / BYE retransmission. I suspect this would have caused issues for
 any within dialog messages with no SDP so glad it is resolved now.<br>
<br>
<span style="font-family:"Courier New",serif">INFO: app_python3 [apy_kemi.c:1820]: sr_apy_kemi_exec_func(): alert - action KSR.rtpengine.rtpengine_manage(...) took too long [1003089 ms] (<a href="file://(null)">file:(null)</a> func:(null) line:252)<br>
<br>
</span>Thanks for the help tracking this down, it was proving a bit of a pain but a fresh pair of eyes can see things familiar ones sometimes cannot.
<o:p></o:p></p>
<p class="MsoNormal"> <br>
<br>
<o:p></o:p></p>
<div>
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black;mso-fareast-language:EN-GB">Lewis
</span></b><span style="mso-fareast-language:EN-GB"><o:p></o:p></span></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 lang="EN-US" style="mso-fareast-language:EN-GB">From:</span></b><span lang="EN-US" style="mso-fareast-language:EN-GB"> Daniel-Constantin Mierla <miconda@gmail.com>
<br>
<b>Sent:</b> 31 August 2022 11:21<br>
<b>To:</b> Kamailio (SER) - Users Mailing List <sr-users@lists.kamailio.org>; Lewis Hutchinson <lewis.hutchinson@missionlabs.co.uk><br>
<b>Subject:</b> Re: [SR-Users] Intermittent delays relaying BYE (up to 1s)<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>First, most of the module functions return negative or positive integer values, not boolean. You have to check with <0 for what's usually false in native kamailio.cfg if conditions and >0 for true.<span style="mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p>Then, also double check it does not execute it via a different config path, like the branch route callback (which happens in the default native kamailio.org).<o:p></o:p></p>
<p>Cheers,<br>
Daniel<o:p></o:p></p>
<div>
<p class="MsoNormal">On 31.08.22 12:00, Lewis Hutchinson wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoPlainText">Ok so making progress but still a little confused, hopefully this forum can shed some light on this behaviour.<br>
<br>
Using the hints provided (thanks all so far) and the latency logging from the cookbook I have managed to isolate the issue down to RTPengine introducing the delay.<br>
<br>
<span style="font-family:"Courier New",serif">INFO: app_python3 [apy_kemi.c:1820]: sr_apy_kemi_exec_func(): alert - action KSR.rtpengine.rtpengine_manage(...) took too long [1003089 ms] (<a href="file://(null)">file:(null)</a> func:(null) line:252)</span><br>
<br>
What is confusing is, I don’t believe this block should be being called.<br>
<br>
when the BYE is triggered, it routes to <span style="font-family:"Courier New",serif">
ksr_route_withindlg</span> <br>
<br>
<span style="font-family:"Courier New",serif">        # handle requests within SIP dialogs</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">        if self.ksr_route_withindlg(msg)==-255 :</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">            return 1</span><br>
<br>
<br>
from within the <span style="font-family:"Courier New",serif">ksr_route_withindlg</span> a check is done to see if any RTPengine work needs doing<br>
<br>
<span style="font-family:"Courier New",serif">    # Handle requests within SIP dialogs</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">    def ksr_route_withindlg(self, msg):</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">        if KSR.siputils.has_totag()<0 :</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">            return 1</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif"> </span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">        # RTPEngine handling for UPDATES & reINVITES with sdp</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">        if self.ksr_route_rtpengine(msg) == -255:</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">            return 1</span><br>
<br>
<br>
RTPengine is configured in a way to step in whenever there is an SDP present based on
<span style="font-family:"Courier New",serif">Content-Type: application/sdp</span><br>
<br>
<span style="font-family:"Courier New",serif">    # RTPengine handle anything with SDP</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">    def ksr_route_rtpengine(self, msg):</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">        if KSR.textops.has_body_type("application/sdp"):</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">           KSR.rtpengine.rtpengine_manage(</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">               "RTP/AVP replace-session-connection replace-origin ICE=remove")</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif"> </span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">        return 1</span><br>
<br>
<br>
What I can understand is why is this being called and erroring introducing the delay when there is no
<span style="font-family:"Courier New",serif">Content-Type: application/sdp</span> in a BYE ???<br>
<br>
<br>
As a quick fix I have put this in which stops the problem (I am sure there is better ways to handle this but for now this works in a DEV environment)<br>
<br>
<span style="font-family:"Courier New",serif">    def ksr_route_rtpengine(self, msg):</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">        if KSR.is_BYE():</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">           return 1</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif"> </span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">        if KSR.textops.has_body_type("application/sdp"):</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">           KSR.rtpengine.rtpengine_manage(</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">               "RTP/AVP replace-session-connection replace-origin ICE=remove")</span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif"> </span><o:p></o:p></p>
<p class="MsoPlainText"><span style="font-family:"Courier New",serif">        return 1</span><br>
<br>
Can anyone see why this would occur? Why is <span style="font-family:"Courier New",serif">
sr_apy_kemi_exec_func(): alert - action KSR.rtpengine.rtpengine_manage(...)</span> even being called for this BYE ? when there is no
<span style="font-family:"Courier New",serif">Content-Type: application/sdp</span><o:p></o:p></p>
<p class="MsoPlainText"><br>
<br>
<br>
<o:p></o:p></p>
<p class="MsoPlainText"><span style="mso-fareast-language:EN-GB">Lewis </span><o:p></o:p></p>
<p class="MsoPlainText"> <o:p></o:p></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-GB"> </span><o:p></o:p></p>
<p class="MsoNormal"> <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">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=05%7C01%7Clewis.hutchinson%40missionlabs.co.uk%7C10e8909d9b5f4cc686b608da8b3a889a%7C97c26f550a7a4661bd8f7b43b50d3f2b%7C0%7C0%7C637975380758802801%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=BFCy1BtWR11lUNNnaRlM%2FO26a2vrujKs%2BEE90ClJQ%2Fw%3D&reserved=0">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=05%7C01%7Clewis.hutchinson%40missionlabs.co.uk%7C10e8909d9b5f4cc686b608da8b3a889a%7C97c26f550a7a4661bd8f7b43b50d3f2b%7C0%7C0%7C637975380758802801%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=d9wW05V47HnLJnW1DZmOqCjzqv9IPMmeHxD%2B7YKJFDo%3D&reserved=0">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=05%7C01%7Clewis.hutchinson%40missionlabs.co.uk%7C10e8909d9b5f4cc686b608da8b3a889a%7C97c26f550a7a4661bd8f7b43b50d3f2b%7C0%7C0%7C637975380758802801%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=rhKynlluDv46CG2RZBNHwzPdMZnVIauAkCPMXhcmZoM%3D&reserved=0">www.twitter.com/miconda</a> -- <a href="https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.linkedin.com%2Fin%2Fmiconda&data=05%7C01%7Clewis.hutchinson%40missionlabs.co.uk%7C10e8909d9b5f4cc686b608da8b3a889a%7C97c26f550a7a4661bd8f7b43b50d3f2b%7C0%7C0%7C637975380758802801%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2TjlFBQO6wIiJyjCxc4KadWf3pj16mLy1jipVDTH46A%3D&reserved=0">www.linkedin.com/in/miconda</a><o:p></o:p></pre>
</div>
</body>
</html>