[SR-Users] pseudovariable values written from app_lua sometimes appear incorrect

elactrum at jamailca.com elactrum at jamailca.com
Wed Sep 26 21:47:13 CEST 2012


Hi,

I am using app_lua to frequently store some data in htable and avp 
entries, using sr.pv.sets. When I read the values using sr.pv.get 
immediately after writing them, they seem correct. However, when I read 
them later from Lua, I have noticed that sometimes the value is 
incorrect or nil. Am I doing something wrong?

The following code uses rtimer to duplicate the problem on startup, 
printing the errors to syslog.

Tested on version: kamailio 3.3.1 (i386/linux) 2d0f6f

###############
# kamailio.cfg
###############
loadmodule	"pv.so"
loadmodule	"xlog.so"
loadmodule	"htable.so"
loadmodule	"rtimer.so"
loadmodule	"app_lua"

modparam("htable", "htable", "status=>size=14;autoexpire=0;")

modparam("rtimer", "timer", "name=ta;interval=10;mode=1")
modparam("rtimer", "exec", "timer=ta;route=LUA_TEST")

# the following path may need to change depending on filesystem setup
modparam("app_lua", "load", "/etc/kamailio/kamailio.lua")

route
{
	route(LUA_TEST);
}

route[LUA_TEST] {

		$var(lua_test_key) = $(pp{s.toupper}) + "::";
		lua_runstring("htable_test([[status=>$var(lua_test_key)]])");
		lua_runstring("avp_test([[status=>$var(lua_test_key)]])");

}

----------------
-- kamailio.lua
----------------
-- Test of sr.pv operations in Lua

function htable_test (namekey)
	local pvar_prefix = "$sht("..namekey
	pvar_test(pvar_prefix)
end

function avp_test ( name )
	local pvar_prefix = "$avp("..name
	pvar_test(pvar_prefix)
end


function pvar_test ( pvar_prefix )

	for value = 10000, 10050 do
		local pvar = pvar_prefix..value..")"
		--sr.log("info", "Lua attempting to set '"..pvar.."' to value 
'"..value.."'")
		sr.pv.sets(pvar, value)
	end

	for value = 10000, 10050 do
		-- now we check what was stored
		local pvar = pvar_prefix..value..")"
		local checkvar = sr.pv.get(pvar)
		if ( tostring(checkvar) ~= tostring(value) ) then
			sr.err(string.format("CHECK: Lua checking pvar '%s' and got value 
'%s' which is NOT '%s'",
				tostring(pvar),
				tostring(checkvar),
				tostring(value)
			))
		end

	end
end
-- end of kamailio.lua


Thanks,

-Andrew



More information about the sr-users mailing list