Synchronizing AGI Calls in Asterisk 1.8 Dialplan


I am using AGI in my dialplan which creates a go process that runs asynchronously and sends a post request. I also use AGI on hangup to send another request. A problem occurs when the call is hanged up quickly. The second AGI starts before the first request was completed.

Is it possible to somehow signal that the post request is done to Asterisk so it can wait before calling the AGI application on hangup? I tried to use set variable as a flag but the variable I set isn’t visible when the call is hangup by the other channel.

My desired workflow is as follows:

  1. AGI (asynchronous) in dialplan execution
  2. Continue dialplan processing
  3. Hangup
  4. Pause if the asynchronous request hasn’t finished
  5. AGI in hangup

Asterisk Version is 1.8

I think everyone has forgotten how 1.8 works in the nearly 9 years since it ceased to be supported. There may be better ways of implementing your requirement, in current versions, but more detail would be needed.

In EVERY version of Asterisk, a call to an AGI script, will pause dialplan execution, until either the script terminates, or the call is hung up.

I would suggest seeing if it was possible to make your external programs handle the synchronization, instead of trying to make Asterisk do it. Both scripts run on the same server, and should be able to check for each others presence.

The first AGI program creates some lock somewhere, with an identifier for the current call. (What the identifier is, doesn’t matter, as long as the chance of two calls having the same identifier at the same time, is sufficiently small.)
The second AGI program looks for the lock, and if present, waits until it’s gone, before proceeding to do whatever it does.

If you have no control of the processes spawned, you could use a wrapper around them, like a shell script, or program written in your favorite language, instead.

But even in current versions of Asterisk, I think you’ll have quite the task handling it in the dialplan, if it’s even possible.

Also I believe the h extension has a limit on how long it is allowed to run, it’s access to data from the channel is very limited, as the channel is destroyed when it is executed.

I think it is more that it is not intended to be used for anything long running. You will get auto-destruct with owner in place messages if you don’t finish quickly, but the channel driver private data structures, and probably things like file descriptors, will be kept until the h extension completes.

I think the dialplan may be allowed to continue as soon as the connection is broken. Obviously no further AGI actions can be performed. Even if there is a wait for the child to complete, it can always spawn background, or even detaches processes.

Plz share the logs so will solve your issue.

If you need to synchronize between different AGI calls, the easiest way would be to have them handled by the same process, via FastAGI.

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