Hangup handlers not always working

Hi There

I’m not sure whats going on here. I’ve configured my dialplan to add a hangup hander in this way:
same => n,Set(CHANNEL(hangup_handler_push)=hangup-handler,${EXTEN},1(args))

I’ve gone through my dial plan to ensure that all of the call flows I control result in this hangup handler being pushed onto the channel.

I would say that 99.9% of the time, this works perfectly and the code in hangup-handler context is executed properly. However, there are occasions, at least a few times a day, where this doesn’t seem to work. I’ve ruled out as much as I can and now am suspecting that there must be occasions when Asterisk is not executing this code.

Is there any circumstance, error, issue, etc where a channel which has a hangup handler would not result in running that code when the channels ends? Any other reason this might be occurring?

We are running Asterisk 16.12.0.

Your hangup_handler might not be getting executed because a hang up is done before the Set has had a chance to execute and setup the handler. Is that a possibility in your case?
I guess I should assume that you are enabling the handler before using an application like Dial(), but if you’re receiving a call, where you place the Set() to enable the handler could make a difference if not done soon enough.

I don’t think it will detect the hangup until control returns to the dialplan interpreter. Hangups are polled for by the code of applications.

If an application does poll for hangup and detect it, it will return an non-zero return code, which will get logged at the recommended verbose level 3 or higher.

When you have this error can you do a pjsip show channels ?
Maybe the calls stay locked because of some missing sip response from a misconfigured phone or trunk.

Looking at pjsip show channels, they are always closed. Its not as though Asterisk thinks the channel is still active.

I am pushing the hangup_hander onto the channel right at its very beginning, before we do any other steps/dial/etc.