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.
- -- Connect to a database
- local dbh = freeswitch.Dbh("pgsql://hostaddr=127.0.0.1
dbname=database user=username password='password'
application_name='my-lua-script'")
- assert(dbh:connected());
- -- Execute SQL
- dbh:query(string.format("SELECT COUNT(*) as \"MyCount\" FROM
\"MyTable\" WHERE ColA = '%s'", argv[1]), function(row)
- --freeswitch.consoleLog("INFO", "Results: " ..
row.MyCount)
-
- dbh:release()
-
- if (row.MyCount== '1') then
- freeswitch.consoleLog("INFO", "User is joining
conference at " .. argv[1])
-
- session:answer()
- session:execute("conference", argv[1] .. "@wideband")
- end
- session:hangup()
- 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@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:
- I don't use `dbh` after line 8. So where does the error come
from?
- How can I stop the error?
- How can I rewrite the lua script to have both a) non-crashing
FS and b) reusing of connection?
Regards,
Bernhard