Ok, got it :-)
I'm new to lua, got this script based on the FS 1.8 book example script.  
Bleg session is in Aleg thread entirely in that example.

Anyway, I've separated sessions and it works. Thank you a lot, Brian!

Regards, Tim

пн, 1 мар. 2021 г. в 22:04, Brian West <brian@freeswitch.com>:
That's because the second legs Lua is running in the first legs session thread.  So it can't hang up yet.

On Fri, Feb 26, 2021 at 3:40 PM Тимур Ситдиков <sitdikovt@gmail.com> wrote:
Hi Brian!
Yes, B hangs up right after pick up. Also there's an error about non available channels in console.



сб, 27 февр. 2021 г., 02:07 Brian West <brian@freeswitch.com>:
Tim,

Based on your description, I would guess that the B-Leg hangs up when they answer after the a-leg is gone??

/b




On Fri, Feb 26, 2021 at 12:42 PM Тимур Ситдиков <sitdikovt@gmail.com> wrote:
Hi all. Need help with a simple call script.
I'm got this in dialplan
<extension name="call_lua_home"> 
      <condition field="destination_number" expression="^(1007)$">
        <!-- <action application="set" data="session_in_hangup_hook=true"/> --> For hangup hook try
        <action application="lua" data="fork.lua"/>
      </condition>
</extension>    
And this in fork.lua
if session:ready() then
api = freeswitch.API()
contact = api:execute("sofia_contact", "*/1007@compA.com");
caller = session:getVariable("caller_id_number");
session1 = freeswitch.Session("{origination_caller_id_name="..caller.."}[leg_timeout=30]"..contact.."");
-- session:setHangupHook("HangupHook");
if session1:ready() then
    freeswitch.bridge(session, session1);
end
freeswitch.consoleLog("WARNING","=====SCRIPT END\n");
session:hangup()
end 

When Caller is hanging up before B-leg answers - Bleg is continuing to ring. There are still 2 channels in 'show channels' after A-leg hangs up.
I want to drop B-leg when A-leg hangs up. Is it possible?

UPD Tried to use hangup hook. It works with stramFile, but no luck with session.
function HangupHook(s, status)
    freeswitch.consoleLog("WARNING","Event fired breaking out\n");
    return exit;
    -- return die;
end

session:answer();
session:setHangupHook("HangupHook");
while (session:ready() == true) do

    session:streamFile("/usr/share/freeswitch/sounds/en/us/callie/ivr/16000/ivr-on_hold_indefinitely.wav");
    -- session1 = freeswitch.Session("{origination_caller_id_name="..caller.."}[leg_timeout=30]"..contact.."");
end
freeswitch.consoleLog("WARNING","=====SCRIPT END\n");
session:hangup()
end

Can anyone help me with this?

Thanks! Regards,Tim
_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com


--

Brian West | Co-founder and Developer

Need Commercial support? email sales@freeswitch.com

FreeSWITCH Solutions | 17345 Civic Drive #2531 Brookfield, WI 53045

Email: brian@freeswitch.com

Mobile: 918-424-9378

Website: https://www.FreeSWITCH.com

https://www.facebook.com/signalwireinc?src=email https://twitter.com/freeswitch

_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com
_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com


--

Brian West | Co-founder and Developer

Need Commercial support? email sales@freeswitch.com

FreeSWITCH Solutions | 17345 Civic Drive #2531 Brookfield, WI 53045

Email: brian@freeswitch.com

Mobile: 918-424-9378

Website: https://www.FreeSWITCH.com

https://www.facebook.com/signalwireinc?src=email https://twitter.com/freeswitch

_________________________________________________________________________

The FreeSWITCH project is sponsored by SignalWire https://signalwire.com
Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services.
Build your next product on our scalable cloud platform.

Join our online community to chat in real time https://signalwire.community

Professional FreeSWITCH Services
sales@freeswitch.com
https://freeswitch.com

Official FreeSWITCH Sites
https://freeswitch.com/oss
https://freeswitch.org/confluence
https://cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
https://freeswitch.com