#581 $var variables cleanup on new request

core (110)

I found that in my script I do something like (the same tail of every log message is because of m4 macros):

route {
xlog("L_INFO", "[MAIN] log message [$var(info)]");
$var(info) = "blablabla";
xlog("L_INFO", "[MAIN] another message [$var(info)]");

Interesting that in first xlog the $var(info) is not null !
And instead of "null" I see there something interesting values from other client's requests.

I think we should clean up all $var variables before request, shouldn't we?


  • Robert Smith

    Robert Smith - 2012-11-13

    I've been bitten by this before, but it's intentional. From the docs:


    1. if you want to start using a script variable in a route, better initialize it with same value (or reset it), otherwise you may inherit a value from a previous route that was executed by the same process.
    3. the value of script variables persists over a OpenSIPS process.

    So you can either initialize it to the same default value every time, or you can use something transactional instead (like avp's).

  • Bogdan-Andrei Iancu

    Hi Nick,

    The $var() are on purpose process persistent - they are not ever reset. You need to take care in script and reset it before using it.

    The fact they are process persistent may help you to pass values between different routes (like requests and branch route) when the routes are triggered in the same process (in a row, like onreply + failure)


  • Bogdan-Andrei Iancu

    • assigned_to: nobody --> bogdan_iancu
    • status: open --> open-invalid
  • Vladut-Stefan Paiu

    • status: open-invalid --> closed-invalid

Log in to post a comment.