<div dir="ltr">This has been super-helpful, Eric. However, the 

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">handleHangupByPeer</span> priorities below are still not run when the peer hangs-up. The last line in the cli when the peer hangs-up is still:<div>Strict RTP learning complete - Locking on source address</div><div>(Although sometimes there is also: Retransmission timeout reached on transmission)<br><div><br></div><div><div> same => n(callPeer),Set(GLOBAL(CB${IndexIntoPeers}CurrentCallsCount)=$[${PeerCurrentCallsCount} + 1])</div><div> ; Ensure that hangup by caller/inbound-channel will invoke handleHangupByCaller.</div><div> same => n,Set(CHANNEL(hangup_handler_push)=handleHangupByCaller,s,1(args))</div><div> same => n,Set(AddressToReachPeer=SIP/${EXTEN:0:4}@${PeerBeingConsidered})</div><div> ; Ensure that the channel of the peer (i.e. outbound-channel) is configured with hangup handler.</div><div> same => n,Dial(${AddressToReachPeer},,b(beforeDialingPeerConfigureItsChannelForPeerHangupHandling^s^1))</div><div> same => n,Hangup</div><div> </div><div>[beforeDialingPeerConfigureItsChannelForPeerHangupHandling]</div><div>exten => s,1,Set(CHANNEL(hangup_handler_push)=handleHangupByPeer,s,1(args))</div><div> same => n,Return</div><div> </div><div>[handleHangupByPeer]</div><div> ; Ensure that GLOBAL(CB${IndexIntoPeers}CurrentCallsCount) is decremented after hangup, and end-of-call-epoch is set.</div><div>exten => s,1,NoOp(${PeerBeingConsidered} peer channel: Entered handleHangupByCallerOrPeer Calls ${CB${IndexIntoPeers}CurrentCallsCount})</div><div> same => n,Set(GLOBAL(CB${IndexIntoPeers}CurrentCallsCount)=$[${CB${IndexIntoPeers}CurrentCallsCount} - 1])</div><div> same => n,Set(GLOBAL(${PeerBeingConsidered}EpochAtCallEnd)=${EPOCH})</div><div> same => n,Return</div><div> </div><div>[handleHangupByCaller]</div><div> ; Ensure that GLOBAL(CB${IndexIntoPeers}CurrentCallsCount) is decremented after hangup, and end-of-call-epoch is set.</div><div>exten => s,1,NoOp(${PeerBeingConsidered} caller channel: Entered handleHangupByCallerOrPeer Calls ${CB${IndexIntoPeers}CurrentCallsCount})</div><div> same => n,Set(GLOBAL(CB${IndexIntoPeers}CurrentCallsCount)=$[${CB${IndexIntoPeers}CurrentCallsCount} - 1])</div><div> same => n,Set(GLOBAL(${PeerBeingConsidered}EpochAtCallEnd)=${EPOCH})</div><div> same => n,Return</div></div><div><br></div><div><br></div><div>When the caller hangs-up, <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">handleHangupByCaller is run first, then <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">handleHangupByPeer runs. (And strangely, the value of global <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">CB${IndexIntoPeers}CurrentCallsCount isn't accessible in 

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">handleHangupByPeer.</span>)</span></span></span></div><div><br></div><div>Cheers,</div><div>David</div><div><div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 5, 2018 at 12:58 PM, Eric Wieling <span dir="ltr"><<a href="mailto:ewieling@nyigc.com" target="_blank">ewieling@nyigc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Don't use the _. pattern.  Ever.<br>
<br>
The call has two channels so it needs two hangup handlers, something like this, though I've not tested it.<br>
<br>
[some_context]<br>
exten => _X.,1,Noop<br>
 same => n,Set(CHANNEL(hangup_handler_p<wbr>ush)=my_caller_hangup_handler)<br>
 same => n,Dial(SIP/number@peer,b(pre_d<wbr>ial^s^1))<br>
 same => n,Hangup<br>
<br>
[pre_dial]<br>
exten => s,1,Set(CHANNEL(hangup_handler<wbr>_push)=my_called_hangup_<wbr>handler)<br>
 same => Return<br>
<br>
See: <a href="https://wiki.asterisk.org/wiki/display/AST/Pre-Dial+Handlers" rel="noreferrer" target="_blank">https://wiki.asterisk.org/wiki<wbr>/display/AST/Pre-Dial+Handlers</a><br>
and <a href="https://wiki.asterisk.org/wiki/display/AST/Hangup+Handlers" rel="noreferrer" target="_blank">https://wiki.asterisk.org/wiki<wbr>/display/AST/Hangup+Handlers</a><span class="gmail-"><br>
<br></span></blockquote></div></div></div></div></div></div>