Redirecting a channel busy in an async AGI leaves command queue for the next async AGI

I’m using Asterisk 16.4.0. I have a channel looping in a context, executing an async AGI:

    exten => s,1,While( 1 < 2 )
    same  => n,AGI(agi:async,my_agi_one)
    same  => n,EndWhile()

The AGI feeds it commands with ManagerAction_AGI and returns it to the dialplan:

    EXEC WaitExten 5

While this is going on, I redirect the channel to other-context with ManagerAction_Redirect:

    exten => s,1,AGI(agi:async,my_agi_two)
    same  => n,NoOp(Returned from my_agi_two)
    same  => n,Hangup()

I receive the ManagerEvent_AsyncAGIStart, followed immediately by a ManagerEvent_AsyncAGIEnd, and the channel hangs up. The second AGI doesn’t have an opportunity to execute commands, because once the channel hits that second AGI, it finishes executing the commands in the command queue from the first AGI. In this case, it runs ASYNCAGI BREAK which is what is causing the second AGI to end immediately.

Most of the commands I’ll send to a channel through an AGI execute quickly, so the only time I’ve noticed this is when trying to bridge channels from an AGI by using Application_Bridge with the F option. My solution there was to simply NOT send the ASYNCAGI BREAK knowing where my channel was going to be when it left the bridge anyways (due to the F option).

The problem here is I can’t guarantee that a channel’s AGI command queue is empty when I try to redirect it and it eventually hits another AGI. So while the channel is bridged or running through another dialplan, the leftover AGI commands are sitting there in the queue waiting to sabotage the next async AGI that the channel encounters.

My interim solution is to set a variable and have the Asterisk dialplan execute the WaitExten. This is problematic in all but the simplest of cases as I may have more logic to do within the AGI besides simply waiting. It still doesn’t solve what I see is the main problem where a channel redirected while in an async AGI will keep its leftover command queue to interfere with a later AGI.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.