<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi,<br>
<br>
I'm using the following Lua-Script to check whether a conference
exists and only let a caller join if so.<br>
The script is called via the following dialplan <i><action
application="lua" data="/path/to/script.lua $1" /></i><i> </i>,
where $1 is the destination number.<br>
<br>
<br>
<ol>
<li>-- Connect to a database</li>
<li>local dbh = freeswitch.Dbh("pgsql://hostaddr=127.0.0.1
dbname=database user=username password='password'
application_name='my-lua-script'")</li>
<li>assert(dbh:connected());</li>
<li>-- Execute SQL</li>
<li>dbh:query(string.format("SELECT COUNT(*) as \"MyCount\" FROM
\"MyTable\" WHERE ColA = '%s'", argv[1]), function(row)</li>
<li> --freeswitch.consoleLog("INFO", "Results: " ..
row.MyCount)</li>
<li> </li>
<li> dbh:release()</li>
<li> </li>
<li> if (row.MyCount== '1') then</li>
<li> freeswitch.consoleLog("INFO", "User is joining
conference at " .. argv[1])</li>
<li> </li>
<li> session:answer()</li>
<li> session:execute("conference", argv[1] .. "@wideband")</li>
<li> end</li>
<li> session:hangup()</li>
<li>end)</li>
</ol>
<br>
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:<br>
<br>
2014-10-12 10:32:30.065924 [DEBUG] switch_cpp.cpp:694
CoreSession::hangup<br>
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<br>
2014-10-12 10:32:30.065924 [CRIT] switch_pgsql.c:122 No DB
Connection<br>
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]<br>
2014-10-12 10:32:30.065924 [ERR] freeswitch_lua.cpp:446 DBH NOT
Connected.<br>
2014-10-12 10:32:30.065924 [DEBUG] switch_cpp.cpp:1075
<a class="moz-txt-link-abbreviated" href="mailto:sofia/internal/Alice@my.pbx.com">sofia/internal/Alice@my.pbx.com</a> destroy/unlink session from object<br>
<br>
Now, I could live with that. BUT: The problem is, that sometimes,
when a user leaves the conference, FS crashes.<br>
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. <br>
<br>
Now my questions:<br>
<ol>
<li>I don't use `dbh` after line 8. So where does the error come
from?</li>
<li>How can I stop the error?</li>
<li>How can I rewrite the lua script to have both a) non-crashing
FS and b) reusing of connection?</li>
</ol>
<p><br>
Regards,<br>
Bernhard<br>
</p>
</body>
</html>