[Freeswitch-users] Lua Dialplan Application to turn down FS

Bernhard Wendel bernhard at sessionbird.com
Wed Oct 15 22:45:38 MSD 2014


Hi Chris,

sorry for the delay. Couldn't get to it sooner.

Thanks for your input. It's working smoothly and as expected.

Regards,
Bernhard

Am 13.10.2014 05:04, schrieb Chris Tunbridge:
> Also, i would remove the session:hangup from the lua script, add an 
> extra action to the extension that handles the check (your xml where 
> you call luarun) and have the hangup there, that way if the lua script 
> does not transfer the call, it will automatically hangup as a default 
> action.
>
> On Sun, Oct 12, 2014 at 9:01 PM, Chris Tunbridge <blasterjr at gmail.com 
> <mailto:blasterjr at gmail.com>> wrote:
>
>     John, the matching parenthesis is found on line 17, there's
>     nothing wrong with the syntax of this file.
>
>     Bernhard, what i recommend is setup a separate extension that just
>     does the conference logic for you, then in your lua code, instead
>     of executing the "conference" stuff, simply transfer to your other
>     XML extension that will put the call in a conference.  In my
>     experience, FreeSWITCH automatically releases db handlers when a
>     script exits, and this works fairly well for me.
>
>     So i would remove your dbh:release() code, use a transfer. also
>     make sure to do
>
>     session:setAutoHangup(false)
>
>     before you transfer the call to your separate XML
>
>
>     On Sun, Oct 12, 2014 at 1:25 PM, John <freeswitch at earthspike.net
>     <mailto:freeswitch at earthspike.net>> wrote:
>
>         Bernhard,
>
>         On line 5, you have more '(' than ')'. They need to balance.
>
>         John
>
>
>         On 12/10/14 18:27, Bernhard Wendel wrote:
>>         Hi John,
>>
>>         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?
>>
>>         Regards,
>>         Bernhard
>>
>>
>>         Am 12.10.2014 17:21, schrieb John:
>>>         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
>>>>         <mailto: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  <mailto: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  <mailto: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
>>>
>>>
>>>
>>>         _________________________________________________________________________
>>>         Professional FreeSWITCH Consulting Services:
>>>         consulting at freeswitch.org  <mailto: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  <mailto: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
>>
>>
>>
>>         _________________________________________________________________________
>>         Professional FreeSWITCH Consulting Services:
>>         consulting at freeswitch.org  <mailto: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  <mailto: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
>
>
>         _________________________________________________________________________
>         Professional FreeSWITCH Consulting Services:
>         consulting at freeswitch.org <mailto: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
>         <mailto: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
>
>
>
>
>
> _________________________________________________________________________
> 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/20141015/33fca93f/attachment-0001.html 


Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list