[Asterisk-Dev] Signal timing can bring down Asterisk

Hans Petter Selasky hselasky at c2i.net
Tue Aug 16 03:29:14 MST 2005


On Tuesday 16 August 2005 11:15, Kristian Nielsen wrote:
> Hans Petter Selasky <hselasky at c2i.net> writes:
> > Can the example above be done in some other way, so that I avoid these
> > problems?
>
> I don't follow your arguments, so let's clarify the issue, and maybe you
> can explain how your thoughts fit in. This is how I understand a channel
> driver should be used:
>
> 1. Call tech->requester() to get struct ast_channel *chan.
>
> 2. Now call tech->call() to start an outgoing call on the channel.
>
> 3. Now loop, sleeping in ast_wait*(), processing events (including
>    ANSWER, HANGUP) with tech->read() and tech->write().

There is no ast_wait() in my source code, asterisk 1.0 according to the 
manpage. But there is ast_waitfor().

>
> 4. Terminate the call using ast_softhangup() (which queues a HANGUP
>    event).

Yes, but it is not only the caller that can terminate the call. Also the 
called party can terminate the call.

But the thing is, that when I have a call coming from CAPI or ISDN, I setup an 
"ast_channel", then I call "ast_pbx_start()" and that function will setup a 
_new_ _thread_ that will listen for Asterisk frames and then call 
"tech->read()" and "tech->write()". But I have another thread waiting for 
messages from the CAPI interface, "/dev/capi20", and these two threads will 
race for "ast_hangup" or "ast_softhangup" !

Well, if all of this could be done by one thread, there would be no problem, 
but I have two threads !

>
> 5. Finally, when the channel is completely done with, call
>    tech->hangup(). After this, the channel can no longer be used.

>
> I don't think there is any problems like the races you mention. It is
> the responsibility of the channel driver to make sure that it will not
> reference the struct ast_channel * any more after tech->hangup()
> returns.

Yes, right, but please note that I have two threads running sending signals 
into the same channel. You have probably only got one thread in your model.


> Note that while tech->requestor() allocates the struct ast_channel *, it
> is not freed by tech->hangup(). This is kind of asymetric, perhaps that
> is what is causing your confusion?

I know, you don't get disconnect signals until the system starts dialing out.


--HPS



More information about the asterisk-dev mailing list