Skip to content

Commit

Permalink
[BUGFIX] Fix possible infinite blocking
Browse files Browse the repository at this point in the history
Avoid cases where executing AGI commands (reported as sending SIP messages) might block indefinitely due to a race condition in fetching their response value.

Requires a fix to Celluloid: celluloid/celluloid#456
  • Loading branch information
benlangfeld committed Sep 18, 2014
1 parent f381f4b commit 0c98609
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@
* Bugfix: Prevent Asterisk translator death due to dead DTMF recognizers ([#221](https://github.com/adhearsion/punchblock/pull/221), [adhearsion/adhearsion#479](https://github.com/adhearsion/adhearsion/issues/479))
* Bugfix: Be more intelligent about only stripping true file extensions off filenames for playback on Asterisk ([adhearsion/adhearsion#482](https://github.com/adhearsion/adhearsion/issues/482))
* Bugfix: Handle a corner case crash where a recognition request is interrupted directly after a successful recognition has completed
* Bugfix: Avoid cases where executing AGI commands (reported as sending SIP messages) might block indefinitely due to a race condition in fetching their response value

# [v2.5.2](https://github.com/adhearsion/punchblock/compare/v2.5.1...v2.5.2) - [2014-04-03](https://rubygems.org/gems/punchblock/versions/2.5.2)
* Bugfix: No longer confound start and stop beeps on record commands (#220)
Expand Down
6 changes: 3 additions & 3 deletions lib/punchblock/translator/asterisk/call.rb
Expand Up @@ -254,12 +254,12 @@ def execute_command(command)
# @raises RubyAMI::Error, ChannelGoneError
def execute_agi_command(command, *params)
agi = AGICommand.new Punchblock.new_uuid, channel, command, *params
condition = Celluloid::Condition.new
response = Celluloid::Future.new
register_tmp_handler :ami, name: 'AsyncAGI', [:[], 'SubEvent'] => 'Exec', [:[], 'CommandID'] => agi.id do |event|
condition.signal event
response.signal Celluloid::SuccessResponse.new(nil, event)
end
agi.execute @ami_client
event = condition.wait
event = response.value
return unless event
agi.parse_result event
end
Expand Down
4 changes: 2 additions & 2 deletions spec/punchblock/translator/asterisk/call_spec.rb
Expand Up @@ -1647,7 +1647,7 @@ def grxml_doc(mode = :dtmf)
end

it 'should send an appropriate AsyncAGI AMI action' do
expect_any_instance_of(Celluloid::Condition).to receive(:wait).and_return nil
expect_any_instance_of(Celluloid::Future).to receive(:value).and_return nil
expect(ami_client).to receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'EXEC ANSWER', 'CommandID' => Punchblock.new_uuid).and_return(response)
subject.execute_agi_command 'EXEC ANSWER'
end
Expand All @@ -1656,7 +1656,7 @@ def grxml_doc(mode = :dtmf)
let(:params) { [1000, 'foo'] }

it 'should send the appropriate action' do
expect_any_instance_of(Celluloid::Condition).to receive(:wait).and_return nil
expect_any_instance_of(Celluloid::Future).to receive(:value).and_return nil
expect(ami_client).to receive(:send_action).once.with('AGI', 'Channel' => channel, 'Command' => 'WAIT FOR DIGIT "1000" "foo"', 'CommandID' => Punchblock.new_uuid).and_return(response)
subject.execute_agi_command 'WAIT FOR DIGIT', *params
end
Expand Down

0 comments on commit 0c98609

Please sign in to comment.