Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Avoid commands to be executed while components are shutting down #158

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/punchblock/translator/freeswitch/call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def initialize(id, translator, es_env = nil, stream = nil, media_engine = nil, d
@es_env = es_env || {}
@components = {}
@pending_joins, @pending_unjoins = {}, {}
@block_commands = false
@answered = false
setup_handlers
end
Expand Down Expand Up @@ -80,6 +81,7 @@ def setup_handlers
end

register_handler :es, :event_name => 'CHANNEL_HANGUP' do |event|
@block_commands = true
@components.dup.each_pair do |id, component|
safe_from_dead_actors do
component.call_ended if component.alive?
Expand Down Expand Up @@ -171,6 +173,10 @@ def answered?
end

def execute_command(command)
if @block_commands
command.response = ProtocolError.new.setup :item_not_found, "Could not find a call with ID #{id}", id
return
end
if command.component_id
if component = component_with_id(command.component_id)
component.execute_command command
Expand Down
14 changes: 14 additions & 0 deletions spec/punchblock/translator/freeswitch/call_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,20 @@ class Freeswitch
translator.should_receive(:handle_pb_event).with(expected_end_event).once.ordered
subject.handle_es_event es_event
end

it "should not allow commands to be executed while components are shutting down" do
comp_command = Punchblock::Component::Input.new :grammar => {:value => '<grammar/>'}, :mode => :dtmf
comp_command.request!
component = subject.execute_command comp_command
comp_command.response(0.1).should be_a Ref

subject.async.handle_es_event es_event

comp_command = Punchblock::Component::Input.new :grammar => {:value => '<grammar/>'}, :mode => :dtmf
comp_command.request!
subject.execute_command comp_command
comp_command.response(0.1).should == ProtocolError.new.setup(:item_not_found, "Could not find a call with ID #{subject.id}", subject.id)
end

[
'NORMAL_CLEARING',
Expand Down