adhearsion/adhearsion — pull request #444 by benlangfeld (2014-03-04 18:04:55+00:00)
Title: Outbound calls can receive events before they are placed in the registry for event dispatch

I have an app connected to FreeSWITCH mod_rayo that calls an Asterisk instance on the same LAN. The Asterisk instance answers the call immediately after the INVITE is sent, without signaling ringing. The end result is the following logs:

```
[2014-02-20 21:00:24.449] TRACE Punchblock::Connection::XMPP: SENDING: (/Users/bklang/.rvm/gems/ruby-2.1.0/gems/blather-1.0.0/lib/blather/client/client.rb:149:in `write')

[2014-02-20 21:00:24.472] TRACE Punchblock::Connection::XMPP: RECEIVING (iq)

[2014-02-20 21:00:24.472] TRACE Punchblock::Connection::XMPP: RECEIVING (presence)

[2014-02-20 21:00:24.475] WARN Adhearsion::PunchblockPlugin::Initializer: Event received for inactive call ed75f6da-9a9b-11e3-a13f-d1a5e1dcb2c6: #
[2014-02-20 21:00:29.695] TRACE Punchblock::Connection::XMPP: RECEIVING (presence)

```

Note in particular the warning about a call ID that is inactive.

Here's an example from a working instance, where I artificially delayed answering the channel:

```
[2014-02-20 22:10:32.577] DEBUG Adhearsion::Call: b73b8198-9aa5-11e3-a110-af1914afbcca@freeswitch.local-dev.mojolingo.com: Receiving message: #, recording=nil, fax=nil, fax_metadata={}>
[2014-02-20 22:10:32.579] DEBUG Adhearsion::OutboundCall: @: Executing command #
[2014-02-20 22:10:32.579] TRACE Punchblock::Connection::XMPP: SENDING: (/Users/bklang/.rvm/gems/ruby-2.1.0/gems/blather-1.0.0/lib/blather/client/client.rb:149:in `write')

[2014-02-20 22:10:32.600] TRACE Punchblock::Connection::XMPP: RECEIVING (iq)

[2014-02-20 22:10:32.600] TRACE Punchblock::Connection::XMPP: RECEIVING (presence)

[2014-02-20 22:10:32.603] WARN Adhearsion::PunchblockPlugin::Initializer: Event received for inactive call b9b52758-9aa5-11e3-a115-af1914afbcca: #
[2014-02-20 22:10:35.587] TRACE Punchblock::Connection::XMPP: RECEIVING (presence)

[2014-02-20 22:10:35.589] DEBUG Adhearsion::OutboundCall: b9b52758-9aa5-11e3-a115-af1914afbcca@freeswitch.local-dev.mojolingo.com: Receiving message: #
[2014-02-20 22:10:35.590] INFO Adhearsion::CallController::Dial::Dial: fb627f1c-6fcd-42bb-9f7f-a5950a734e4b: #dial joining call b9b52758-9aa5-11e3-a115-af1914afbcca to b73b8198-9aa5-11e3-a110-af1914afbcca
```

Note the warning is still present, but now it's on the `` element. I suspect this is a race condition after the ``.