[Freeswitch-users] Lua Dialplan Application to turn down FS
John
freeswitch at earthspike.net
Sun Oct 12 19:21:53 MSD 2014
It looks like the parentheses don't match on line 5.
John
On 12/10/14 11:45, Bernhard Wendel wrote:
> Hi,
>
> 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'
> application_name='my-lua-script'")
> 3. assert(dbh:connected());
> 4. -- Execute SQL
> 5. dbh:query(string.format("SELECT COUNT(*) as \"MyCount\" FROM
> \"MyTable\" WHERE ColA = '%s'", argv[1]), function(row)
> 6. --freeswitch.consoleLog("INFO", "Results: " .. row.MyCount)
> 7.
> 8. dbh:release()
> 9.
> 10. if (row.MyCount== '1') then
> 11. freeswitch.consoleLog("INFO", "User is joining conference
> at " .. argv[1])
>12.
> 13. session:answer()
> 14. session:execute("conference", argv[1] .. "@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 Connected.
> 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?
>
>
> Regards,
> Bernhard
>
>
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://confluence.freeswitch.org
> http://www.cluecon.com
>
>
>
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20141012/c6d546bc/attachment-0001.html
Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users
mailing list