[OpenSIPS-Users] Second Contact when sending 302 Redirect using async avp_db_query

Jon Abrams ffshoh at gmail.com
Fri Mar 6 22:56:11 EST 2020


Async does indeed trigger the transaction creation. You may need to update
the $ru variable and not use the append_to_reply. Or at least that's how I
solved this in the past.

else if ($var(db_res) == -1)
{
update_stat("mysql_result_error", "+1");
$ru = "<sip:" + $rU + "@" + $si + ":" + $sp + ";npdi"  + ">";
#append_to_reply("Contact: $var(ct)\r\n");
sl_send_reply("302", "Redirect");
$var(processingTime) = $Ts * 1000 + $Tsm/1000 - $avp(startTime);
xlog("L_ERR", "TRACE:ROUTE:MYSQL_ERROR src=$si:$sp dst=$Ri:$Rp From=$fU
To=$rU ID=$ci Time=$var(processingTime)\n");
exit();
}

I ran a setup similar to this for about 6 years under heavy volume
(1000-2000 CPS sustained). Two X5600 Xeons boxes were used, one with
OpenSIPs and one with MySQL holding the LRN data pinned in memory. No async
or caching.
I would caution somewhat about using the caching (and possibly the async),
as memory fragmentation may become a problem after sustained usage.

- Jon Abrams

On Fri, Mar 6, 2020 at 4:09 PM Calvin Ellison <calvin.ellison at voxox.com>
wrote:

> The scenario is a SIP-MySQL proxy that performs LRN queries and replies
> with 302 Redirect and Contact including npdi and optional rn parameters.
> Cache_db is also used. This has worked as intended using the SL module
> without async.
>
> After refactoring to use async(avp_db_query()), there is now an additional
> Contact in the 302 Redirect only if the async() happens. When the RN is
> found in the cache there is only the single intended Contact.
>
> I suspect the difference has something to do with async using the TM
> module and it's probably a simple mistake. What magic is required to send
> only the desired Contact after async?
>
> Here's the cached chunk:
>                 if($Rp != "5061" && !is_present_hf("X-LNP-Refresh") &&
> cache_fetch("local", "$rU", $avp(10)))
>                 {
>                         $avp(lrn) = $avp(10);
>                         $avp(resultType) = "CACHED";
>                         update_stat("cached_results", "+1");
>                         route(continue);
>                 }
> ...
>
> route [continue]
> {
>  if($Rp != "5061" )
>         cache_store("local", "$rU", "$avp(lrn)", $avp(timeout));
>
>         $var(rn) = $(avp(lrn){csv.value,0});
>         $var(ct) = "<sip:" + $rU + "@" + $si + ":" + $sp + ";npdi";
>         if($(var(rn){s.len}) != 0)
>                 $var(ct) = $var(ct) + ";rn=" + $var(rn);
>         $var(ct) = $var(ct) + ">";
>         append_to_reply("Contact: $var(ct)\r\n");
>
>         sl_send_reply("302", "Redirect");
>         $var(processingTime) = $Ts * 1000 + $Tsm/1000 - $avp(startTime);
> }
>
>
> Not-cached does this:
>
> async(avp_db_query("call lrn.sqlrn('$var(number)')",
> "$avp(11);$avp(12);$avp(13)"), resume_lnp);
>
> ...
>
> route [resume_lnp]
> {
>         $var(db_res) = $retcode;
>         if ($var(db_res) && is_avp_set("$avp(11)"))
>         {
>                 update_stat("mysql_result_number", "+1");
>                 $var(number) = $avp(11);
>                 if ($avp(11) =~ "^[2-9][0-9]{9}$")
>                         $var(number) = "1" + $avp(11);
>
>                 $avp(lrn) = $var(number) + "," + $avp(12) + "," + $avp(13);
>                 $avp(resultType) = "MYSQL";
>         }
>         else if ($var(db_res) == -1)
>         {
>                 update_stat("mysql_result_error", "+1");
>                 $var(ct) = "<sip:" + $rU + "@" + $si + ":" + $sp + ";npdi"
>  + ">";
>                 append_to_reply("Contact: $var(ct)\r\n");
>                 sl_send_reply("302", "Redirect");
>                 $var(processingTime) = $Ts * 1000 + $Tsm/1000 -
> $avp(startTime);
>                 xlog("L_ERR", "TRACE:ROUTE:MYSQL_ERROR src=$si:$sp
> dst=$Ri:$Rp From=$fU To=$rU ID=$ci Time=$var(processingTime)\n");
>                 exit();
>         }
>         else
>         {
>                 update_stat("mysql_result_empty", "+1");
>                 $avp(resultType) = "MYSQL_EMPTY";
>         }
>         route(continue);
> }
>
>
> Good (cached, no async):
>
> SIP/2.0 302 Redirect
> Via: SIP/2.0/UDP 10.0.2.45:5060;branch=z9hG4bK-27769-1-0
> From: <sip:sipp at 10.0.2.45:5060>;tag=27769SIPpTag001
> To: 17605086443 <sip:17605086443 at 10.0.131.97:5060
> >;tag=a1b3.ecf278993d227a99987b0bccd10b5617
> Call-ID: 1-27769 at 10.0.2.45
> CSeq: 1 INVITE
> Contact: <sip:17605086443 at 10.0.2.45:5060;npdi>
> Content-Length: 0
>
>
> Bad (not cached, async):
>
> SIP/2.0 302 Redirect
> Via: SIP/2.0/UDP 10.0.2.45:5060;branch=z9hG4bK-27753-1-0
> From: <sip:sipp at 10.0.2.45:5060>;tag=27753SIPpTag001
> To: 17605086443 <sip:17605086443 at 10.0.131.97:5060
> >;tag=a1b3.fd3dd7f924d173cf165e3579c8289026
> Call-ID: 1-27753 at 10.0.2.45
> CSeq: 1 INVITE
> Contact: <sip:17605086443 at 10.0.2.45:5060;npdi>
> Contact: <sip:17605086443 at 10.0.131.97:5060>
> Content-Length: 0
>
>
>
> Regards,
>
> *Calvin Ellison*
> Senior Voice Operations Engineer
> calvin.ellison at voxox.com
> +1 (213) 285-0555
>
> -----------------------------------------------
> *voxox.com <http://www.voxox.com/> *
> 5825 Oberlin Drive, Suite 5
> San Diego, CA 92121
> [image: Voxox]
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20200306/47eb6afa/attachment.html>


More information about the Users mailing list