FreeSWITCH

Unable to exit lua script in hangup handler

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: mod_lua
  • Platform:
    Linux x86_64/gcc
  • Uname:
    Linux freeswitch 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux
  • CPU Info:
    Hide
    processor : 0
    vendor_id : GenuineIntel
    cpu family : 6
    model : 15
    model name : Intel(R) Xeon(R) CPU X5365 @ 3.00GHz
    stepping : 11
    cpu MHz : 2992.500
    cache size : 4096 KB
    fpu : yes
    fpu_exception : yes
    cpuid level : 10
    wp : yes
    flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx lm constant_tsc arch_perfmon pebs bts tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni ssse3 cx16 hypervisor lahf_lm dts
    bogomips : 5985.00
    clflush size : 64
    cache_alignment : 64
    address sizes : 40 bits physical, 48 bits virtual
    power management:

    processor : 1
    vendor_id : GenuineIntel
    cpu family : 6
    model : 15
    model name : Intel(R) Xeon(R) CPU X5365 @ 3.00GHz
    stepping : 11
    cpu MHz : 2992.500
    cache size : 4096 KB
    fpu : yes
    fpu_exception : yes
    cpuid level : 10
    wp : yes
    flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx lm constant_tsc arch_perfmon pebs bts tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni ssse3 cx16 hypervisor lahf_lm dts
    bogomips : 5985.00
    clflush size : 64
    cache_alignment : 64
    address sizes : 40 bits physical, 48 bits virtual
    power management:
    Show
    processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 15 model name : Intel(R) Xeon(R) CPU X5365 @ 3.00GHz stepping : 11 cpu MHz : 2992.500 cache size : 4096 KB fpu : yes fpu_exception : yes cpuid level : 10 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx lm constant_tsc arch_perfmon pebs bts tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni ssse3 cx16 hypervisor lahf_lm dts bogomips : 5985.00 clflush size : 64 cache_alignment : 64 address sizes : 40 bits physical, 48 bits virtual power management: processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 15 model name : Intel(R) Xeon(R) CPU X5365 @ 3.00GHz stepping : 11 cpu MHz : 2992.500 cache size : 4096 KB fpu : yes fpu_exception : yes cpuid level : 10 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx lm constant_tsc arch_perfmon pebs bts tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni ssse3 cx16 hypervisor lahf_lm dts bogomips : 5985.00 clflush size : 64 cache_alignment : 64 address sizes : 40 bits physical, 48 bits virtual power management:
  • GCC Version:
    gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
  • FreeSWITCH GIT Revision:
    FreeSWITCH Version 1.0.head (git-5783078 2012-01-24 17-38-36 -0600)
  • Reproduced with GIT HEAD?:
    FreeSWITCH Version 1.0.head (git-5783078 2012-01-24 17-38-36 -0600)
  • lsb_release:
    Hide
    LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
    Distributor ID: CentOS
    Description: CentOS release 6.2 (Final)
    Release: 6.2
    Codename: Final
    Show
    LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 6.2 (Final) Release: 6.2 Codename: Final
  • Description:
    Hide
    i'm unable to exit a lua script in the hangup handler.

    Script:


    function on_hangup(s,status)
            freeswitch.consoleLog("NOTICE","---- on_hangup: "..status.."\n");
            error();
    end

    freeswitch.consoleLog("NOTICE","---- ANSWER:\n");
    session:answer();
    freeswitch.consoleLog("NOTICE","---- SETHOOK: \n");
    session:setHangupHook("on_hangup");

    while (session:ready() == true) do
            freeswitch.consoleLog("NOTICE","---- START OF LOOP \n");
            freeswitch.consoleLog("NOTICE","---- STREAMFILE \n");
            session:streamFile("/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-on_hold_indefinitely.wav");
            freeswitch.consoleLog("NOTICE","---- END OF SCRIPT 1 -> HANGUP\n");
    end

    freeswitch.consoleLog("NOTICE","---- END OF SCRIPT 2 -> HANGUP\n");
    session:hangup()

    Output:
    2012-01-25 12:10:19.936097 [NOTICE] switch_channel.c:930 New Channel sofia/internal/2001@192.168.20.73 [2b1cd9f6-4745-11e1-8c71-0d2938abf0b5]
    2012-01-25 12:10:19.936097 [INFO] mod_dialplan_xml.c:481 Processing B#-FS-2001 <2001>->3001 in context default
    2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- ANSWER:
    2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:599 Channel [sofia/internal/2001@192.168.20.73] has been answered
    2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- SETHOOK:
    2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- START OF LOOP
    2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- STREAMFILE
    2012-01-25 12:10:21.116050 [NOTICE] sofia.c:624 Hangup sofia/internal/2001@192.168.20.73 [CS_EXECUTE] [NORMAL_CLEARING]
    2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- on_hangup: hangup
    2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- END OF SCRIPT 1 -> HANGUP
    2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- END OF SCRIPT 2 -> HANGUP
    2012-01-25 12:10:21.116050 [NOTICE] switch_core_session.c:1398 Session 2 (sofia/internal/2001@192.168.20.73) Ended
    2012-01-25 12:10:21.116050 [NOTICE] switch_core_session.c:1400 Close Channel sofia/internal/2001@192.168.20.73 [CS_DESTROY]

    Why does the hangup handler return and the rest of the script is executed ?
    I event tried "do return end;" , "exit;" ," exit();" instead of "error(); - none of them works.
    Also the following code does not work:

    function on_hangup(s,status)
            freeswitch.consoleLog("NOTICE","---- on_hangup: "..status.."\n");
            if(session:ready() == false) then
                    freeswitch.consoleLog("NOTICE","---- SESSION NOT READY -> EXIT:\n");
                    --session:destroy();
                    --session:detach();
                    --error();
                    do return end;
            end
            freeswitch.consoleLog("NOTICE","---- END OF HANGUP\n");
    end



    If i put the same logic into javascript, the hook works and the script is terminated:

    function on_hangup(s,status)
    {
            console_log("NOTICE","---- hangup "+status+"\n");
            return "exit";
    }

    console_log("NOTICE","---- ANSWER\n");
    session.answer();
    console_log("NOTICE","---- ANSWER\n");
    session.setHangupHook(on_hangup);

    while(session.ready())
    {
            console_log("NOTICE","---- START OF LOOP\n");
            session.streamFile("/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-on_hold_indefinitely.wav");
            console_log("NOTICE","---- END OF LOOP\n");
    }
    console_log("NOTICE","---- END OF SCRIPT\n");
    session.hangup();


    2012-01-25 12:13:08.396041 [NOTICE] switch_channel.c:930 New Channel sofia/internal/2001@192.168.20.73 [8f85a15c-4745-11e1-8c76-0d2938abf0b5]
    2012-01-25 12:13:08.396041 [INFO] mod_dialplan_xml.c:481 Processing B#-FS-2001 <2001>->3002 in context default
    2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- ANSWER
    2012-01-25 12:13:08.396041 [NOTICE] mod_spidermonkey.c:2068 Channel [sofia/internal/2001@192.168.20.73] has been answered
    2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- ANSWER
    2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- START OF LOOP
    2012-01-25 12:13:09.875996 [NOTICE] sofia.c:624 Hangup sofia/internal/2001@192.168.20.73 [CS_EXECUTE] [NORMAL_CLEARING]
    2012-01-25 12:13:09.875996 [NOTICE] hangup.js:2 ---- hangup hangup
    2012-01-25 12:13:09.875996 [NOTICE] switch_core_session.c:1398 Session 3 (sofia/internal/2001@192.168.20.73) Ended
    2012-01-25 12:13:09.875996 [NOTICE] switch_core_session.c:1400 Close Channel sofia/internal/2001@192.168.20.73 [CS_DESTROY]




    Show
    i'm unable to exit a lua script in the hangup handler. Script: function on_hangup(s,status)         freeswitch.consoleLog("NOTICE","---- on_hangup: "..status.."\n");         error(); end freeswitch.consoleLog("NOTICE","---- ANSWER:\n"); session:answer(); freeswitch.consoleLog("NOTICE","---- SETHOOK: \n"); session:setHangupHook("on_hangup"); while (session:ready() == true) do         freeswitch.consoleLog("NOTICE","---- START OF LOOP \n");         freeswitch.consoleLog("NOTICE","---- STREAMFILE \n");         session:streamFile("/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-on_hold_indefinitely.wav");         freeswitch.consoleLog("NOTICE","---- END OF SCRIPT 1 -> HANGUP\n"); end freeswitch.consoleLog("NOTICE","---- END OF SCRIPT 2 -> HANGUP\n"); session:hangup() Output: 2012-01-25 12:10:19.936097 [NOTICE] switch_channel.c:930 New Channel sofia/internal/2001@192.168.20.73 [2b1cd9f6-4745-11e1-8c71-0d2938abf0b5] 2012-01-25 12:10:19.936097 [INFO] mod_dialplan_xml.c:481 Processing B#-FS-2001 <2001>->3001 in context default 2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- ANSWER: 2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:599 Channel [sofia/internal/2001@192.168.20.73] has been answered 2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- SETHOOK: 2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- START OF LOOP 2012-01-25 12:10:19.936097 [NOTICE] switch_cpp.cpp:1227 ---- STREAMFILE 2012-01-25 12:10:21.116050 [NOTICE] sofia.c:624 Hangup sofia/internal/2001@192.168.20.73 [CS_EXECUTE] [NORMAL_CLEARING] 2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- on_hangup: hangup 2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- END OF SCRIPT 1 -> HANGUP 2012-01-25 12:10:21.116050 [NOTICE] switch_cpp.cpp:1227 ---- END OF SCRIPT 2 -> HANGUP 2012-01-25 12:10:21.116050 [NOTICE] switch_core_session.c:1398 Session 2 (sofia/internal/2001@192.168.20.73) Ended 2012-01-25 12:10:21.116050 [NOTICE] switch_core_session.c:1400 Close Channel sofia/internal/2001@192.168.20.73 [CS_DESTROY] Why does the hangup handler return and the rest of the script is executed ? I event tried "do return end;" , "exit;" ," exit();" instead of "error(); - none of them works. Also the following code does not work: function on_hangup(s,status)         freeswitch.consoleLog("NOTICE","---- on_hangup: "..status.."\n");         if(session:ready() == false) then                 freeswitch.consoleLog("NOTICE","---- SESSION NOT READY -> EXIT:\n");                 --session:destroy();                 --session:detach();                 --error();                 do return end;         end         freeswitch.consoleLog("NOTICE","---- END OF HANGUP\n"); end If i put the same logic into javascript, the hook works and the script is terminated: function on_hangup(s,status) {         console_log("NOTICE","---- hangup "+status+"\n");         return "exit"; } console_log("NOTICE","---- ANSWER\n"); session.answer(); console_log("NOTICE","---- ANSWER\n"); session.setHangupHook(on_hangup); while(session.ready()) {         console_log("NOTICE","---- START OF LOOP\n");         session.streamFile("/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-on_hold_indefinitely.wav");         console_log("NOTICE","---- END OF LOOP\n"); } console_log("NOTICE","---- END OF SCRIPT\n"); session.hangup(); 2012-01-25 12:13:08.396041 [NOTICE] switch_channel.c:930 New Channel sofia/internal/2001@192.168.20.73 [8f85a15c-4745-11e1-8c76-0d2938abf0b5] 2012-01-25 12:13:08.396041 [INFO] mod_dialplan_xml.c:481 Processing B#-FS-2001 <2001>->3002 in context default 2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- ANSWER 2012-01-25 12:13:08.396041 [NOTICE] mod_spidermonkey.c:2068 Channel [sofia/internal/2001@192.168.20.73] has been answered 2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- ANSWER 2012-01-25 12:13:08.396041 [NOTICE] hangup.js:1 ---- START OF LOOP 2012-01-25 12:13:09.875996 [NOTICE] sofia.c:624 Hangup sofia/internal/2001@192.168.20.73 [CS_EXECUTE] [NORMAL_CLEARING] 2012-01-25 12:13:09.875996 [NOTICE] hangup.js:2 ---- hangup hangup 2012-01-25 12:13:09.875996 [NOTICE] switch_core_session.c:1398 Session 3 (sofia/internal/2001@192.168.20.73) Ended 2012-01-25 12:13:09.875996 [NOTICE] switch_core_session.c:1400 Close Channel sofia/internal/2001@192.168.20.73 [CS_DESTROY]
  • Environment:
    centos 6.2 x64

Activity

Hide
Jeff Lenk added a comment - 26/Jan/12 9:26 AM
mod_spidermonkey is different than all the other language modules as in that its wrapper was created by hand which allows this special behavior you are describing to occur. mod_lua is auto generated by SWIG and does not have this ability on it own(AFAIK). You will have to place checks in the code to handle flow as required by your needs.
Show
Jeff Lenk added a comment - 26/Jan/12 9:26 AM mod_spidermonkey is different than all the other language modules as in that its wrapper was created by hand which allows this special behavior you are describing to occur. mod_lua is auto generated by SWIG and does not have this ability on it own(AFAIK). You will have to place checks in the code to handle flow as required by your needs.
Hide
Gerald Weber added a comment - 26/Jan/12 11:08 AM
ok,but this means i have to do a "if session:ready() == false then error() end" after every command in my script.
If i have a script that is a couple of hundreds lines long..thats a lot of (unnecessary) work and calls.

other example:
consider database operations in the code.they all get executed until the end of the script even if the call is no longer existing.
which can lead to unexcpeted results if you dont check if the session is still alive before EVERY (non-api ?) command.

i think there should be a way to end the script on a central point when the call is hangup.

Show
Gerald Weber added a comment - 26/Jan/12 11:08 AM ok,but this means i have to do a "if session:ready() == false then error() end" after every command in my script. If i have a script that is a couple of hundreds lines long..thats a lot of (unnecessary) work and calls. other example: consider database operations in the code.they all get executed until the end of the script even if the call is no longer existing. which can lead to unexcpeted results if you dont check if the session is still alive before EVERY (non-api ?) command. i think there should be a way to end the script on a central point when the call is hangup.
Hide
Git added a comment - 27/Jan/12 7:03 PM
Repository: freeswitch
Branch: refs/heads/master
Commit: 09ad887 http://fisheye.freeswitch.org/changelog/freeswitch.git/?cs=09ad887
Closed By: anthm@freeswitch.org

Comment:
FS-3841 --resolve ok return the string "die" or "exit" from hanguphook to cause an error or call s:destroy("any err message"); either should now halt the script


FreeSWITCH Support Contracts and Consulting Services available!

Contact us:
Email: consulting@freeswitch.org
Web: http://www.freeswitch.org
Phone: +1-918-420-9266
Tollfree: +1-877-742-2583
Fax: +1-918-420-9267
iNum: +883 5100 1420 9266


Come To ClueCon in August to learn more about FreeSWITCH and Internet Telephony!
http://www.cluecon.com

Show
Git added a comment - 27/Jan/12 7:03 PM Repository: freeswitch Branch: refs/heads/master Commit: 09ad887 http://fisheye.freeswitch.org/changelog/freeswitch.git/?cs=09ad887 Closed By: anthm@freeswitch.org Comment: FS-3841 --resolve ok return the string "die" or "exit" from hanguphook to cause an error or call s:destroy("any err message"); either should now halt the script FreeSWITCH Support Contracts and Consulting Services available! Contact us: Email: consulting@freeswitch.org Web: http://www.freeswitch.org Phone: +1-918-420-9266 Tollfree: +1-877-742-2583 Fax: +1-918-420-9267 iNum: +883 5100 1420 9266 Come To ClueCon in August to learn more about FreeSWITCH and Internet Telephony! http://www.cluecon.com
Hide
Auto Admin added a comment - 10/Feb/12 8:17 PM
Due to a long period of inactivity (13 or more days), this issue is due to be automatically close within 24 hours.
If this issue is not actually resolved, please reopen it and add appropriate comments to help developers fix the issue.

Thanks,
  Jira Admin
Show
Auto Admin added a comment - 10/Feb/12 8:17 PM Due to a long period of inactivity (13 or more days), this issue is due to be automatically close within 24 hours. If this issue is not actually resolved, please reopen it and add appropriate comments to help developers fix the issue. Thanks,   Jira Admin
Hide
Auto Admin added a comment - 10/Feb/12 8:17 PM
Since there has been no change to the status of this issue, it is being closed for inactivity

Thanks,
  Jira Admin


FreeSWITCH Support Contracts and Consulting Services available!

Contact us:
Email: consulting@freeswitch.org
Web: http://www.freeswitch.org
Phone: +1-918-420-9266
Tollfree: +1-877-742-2583
Fax: +1-918-420-9267
iNum: +883 5100 1420 9266


Come To ClueCon in August to learn more about FreeSWITCH and Internet Telephony!
http://www.cluecon.com

Show
Auto Admin added a comment - 10/Feb/12 8:17 PM Since there has been no change to the status of this issue, it is being closed for inactivity Thanks,   Jira Admin FreeSWITCH Support Contracts and Consulting Services available! Contact us: Email: consulting@freeswitch.org Web: http://www.freeswitch.org Phone: +1-918-420-9266 Tollfree: +1-877-742-2583 Fax: +1-918-420-9267 iNum: +883 5100 1420 9266 Come To ClueCon in August to learn more about FreeSWITCH and Internet Telephony! http://www.cluecon.com

People

Dates

  • Created:
    26/Jan/12 3:44 AM
    Updated:
    10/Feb/12 8:17 PM
    Resolved:
    27/Jan/12 7:03 PM