[Freeswitch-users] Lua Dialplan Application to turn down FS
Bernhard Wendel
bernhard at sessionbird.com
Sun Oct 12 14:45:26 MSD 2014
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20141012/5b77f84b/attachment.html
Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users
mailing list