[Freeswitch-users] Lua Dialplan Application to turn down FS
bernhard at sessionbird.com
Sun Oct 12 21:27:16 MSD 2014
what are you trying to tell me?
Since I'm new to LUA you make me wonder whether there is a syntax error
within my code. It should pop up somewhere, shouldn't it? Because I
haven't found one and the code is actually working.
Or am I missing something?
Am 12.10.2014 17:21, schrieb John:
> It looks like the parentheses don't match on line 5.
> On 12/10/14 11:45, Bernhard Wendel wrote:
>> I'm using the following Lua-Script to check whether a conference
>> exists and only let a caller join if so.
>> The script is called via the following dialplan /<action
>> application="lua" data="/path/to/script.lua $1" />///, where $1 is
>> the destination number.
>> 1. -- Connect to a database
>> 2. local dbh = freeswitch.Dbh("pgsql://hostaddr=127.0.0.1
>> dbname=database user=username password='password'
>> 3. assert(dbh:connected());
>> 4. -- Execute SQL
>> 5. dbh:query(string.format("SELECT COUNT(*) as \"MyCount\" FROM
>> \"MyTable\" WHERE ColA = '%s'", argv), function(row)
>> 6. --freeswitch.consoleLog("INFO", "Results: " .. row.MyCount)
>> 8. dbh:release()
>> 10. if (row.MyCount== '1') then
>> 11. freeswitch.consoleLog("INFO", "User is joining conference
>> at " .. argv)
>> 13. session:answer()
>> 14. session:execute("conference", argv .. "@wideband")
>> 15. end
>> 16. session:hangup()
>> 17. end)
>> Line 8 instructs FS to return the postgres-Connection back to the
>> pool - which is as expected. When a user now leaves the conference,
>> FS throws this errors:
>> 2014-10-12 10:32:30.065924 [DEBUG] switch_cpp.cpp:694 CoreSession::hangup
>> 2014-10-12 10:32:30.065924 [CRIT] switch_pgsql.c:368 An error
>> occurred trying to consume input for query (200): connection pointer
>> is NULL
>> 2014-10-12 10:32:30.065924 [CRIT] switch_pgsql.c:122 No DB Connection
>> 2014-10-12 10:32:30.065924 [ERR] switch_core_sqldb.c:1177 ERR:
>> [SELECT COUNT(*) as "MyCount" FROM "MyTable" WHERE ColA =
>> 'conf-1234'][connection pointer is NULL]
>> 2014-10-12 10:32:30.065924 [ERR] freeswitch_lua.cpp:446 DBH NOT
>> 2014-10-12 10:32:30.065924 [DEBUG] switch_cpp.cpp:1075
>> sofia/internal/Alice at my.pbx.com destroy/unlink session from object
>> Now, I could live with that. BUT: The problem is, that sometimes,
>> when a user leaves the conference, FS crashes.
>> I've narrowed down the main cause to the above lua script. If I
>> comment line 8 out, FS stops crashing. This will also stop FS from
>> reusing Database-Connections.
>> Now my questions:
>> 1. I don't use `dbh` after line 8. So where does the error come from?
>> 2. How can I stop the error?
>> 3. How can I rewrite the lua script to have both a) non-crashing FS
>> and b) reusing of connection?
>> Professional FreeSWITCH Consulting Services:
>> consulting at freeswitch.org
>> Official FreeSWITCH Sites
>> FreeSWITCH-users mailing list
>> FreeSWITCH-users at lists.freeswitch.org
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> Official FreeSWITCH Sites
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
-------------- next part --------------
An HTML attachment was scrubbed...
Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users