You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I tried executing code similar to the example in the README.md, i.e.:
require'ruby_ami'defhandle_event(event,stream)caseevent.namewhen'FullyBooted'puts"The connection was successful. Originating a call."response=stream.send_action'QueueStatus','Queue'=>queueputs"The call origination resulted in #{response.inspect}"endendstream=RubyAMI::Stream.new'127.0.0.1',5038,'manager','password',->(e,stream){handle_evente,stream},Logger.new(STDOUT),10Celluloid::Actor.join(stream)
It seems to deadlock during the send_action call. My hunch is that this example given was originally written for when ruby_ami was using EventMachine instead of Celluloid. I suspect it deadlocks because when send_action is called inside handle_event, the connection.wait that's gets called blocks the thread (or actor or whatever it's called) that should be reading the socket. Hence it's waiting for a response it can't get, it deadlocks.
I was able to fix it by moving the stream.send_action outside of handle_event and put a sleep before it to make sure AMI was fully booted. But I wanted to find out if my theory was correct, and if we should update the README.md with a working example. (If that's the case I can submit a PR)
require'ruby_ami'defhandle_event(event,stream)caseevent.namewhen'FullyBooted'puts"The connection was successful. Originating a call."response=stream.send_action'QueueStatus','Queue'=>'queuename'puts"The call origination resulted in #{response.inspect}"endendstream=RubyAMI::Stream.new'hostname',5038,'manager','password',->(e,stream){handle_evente,stream},Logger.new(STDOUT),10Celluloid::Actor.join(stream)
In stream.rb I added a puts "READING DATA inside loop { receive_data @socket.readpartial(4096) } to see if the loop is running. I also had ngrep running on port 5038 to see if there's any AMI traffic from the asterisk server and there is.
If I comment out the send_action line and the response.inspect line the in the script it runs fine and processes data.
Let me know if there's anything else you need me to do. I'll continue to troubleshoot this myself.
Hey, sorry it's been maybe about a year and a half since I submitted this so my memory isn't entirely fresh. I submitted PR #41 which has my proposed fix, but also adds a unit test which recreates the issue if we can come up with a better solution.
2.5 years later and I'm completely in the dark as to how I'd send an action (and get a response) in response to an event. When a queue member signs in or out, I'd like to get a list of who all is in the queue. I can't for the life of me figure out how I'd do that with this library.
Activity
benlangfeld commentedon Dec 2, 2016
It shouldn't deadlock; the Stream actor should pause the task. This feels more like an implementation bug rather than a documentation bug.
joshaidan commentedon Dec 3, 2016
So running this script:
I get the following:
Then it just stops.
In stream.rb I added a
puts "READING DATAinsideloop { receive_data @socket.readpartial(4096) }to see if the loop is running. I also had ngrep running on port 5038 to see if there's any AMI traffic from the asterisk server and there is.If I comment out the
send_actionline and theresponse.inspectline the in the script it runs fine and processes data.Let me know if there's anything else you need me to do. I'll continue to troubleshoot this myself.
joshaidan commentedon Dec 3, 2016
So, if I change the call to:
This seems to resolve the deadlock, and the call works correctly. Not sure if this is the correct fix; I got a lot of learning about Celluloid to do.
benjaminfauchald commentedon Jul 5, 2018
Did you ever solve this? Seems like putting this async will just have a bunch of connections going until they time out? Doesn't seem very effective?
joshaidan commentedon Jul 5, 2018
Hey, sorry it's been maybe about a year and a half since I submitted this so my memory isn't entirely fresh. I submitted PR #41 which has my proposed fix, but also adds a unit test which recreates the issue if we can come up with a better solution.
awh-tokyo commentedon Feb 5, 2021
2.5 years later and I'm completely in the dark as to how I'd send an action (and get a response) in response to an event. When a queue member signs in or out, I'd like to get a list of who all is in the queue. I can't for the life of me figure out how I'd do that with this library.
ThomasSevestre commentedon Feb 5, 2021
In case it helps...
You can try my eventmachine branch if you want : https://github.com/ThomasSevestre/ruby_ami/tree/eventmachine
awh-tokyo commentedon Mar 1, 2024
@ThomasSevestre Any chance you'd consider releasing your eventmachine branch as a separate gem? I just ran into this problem again.
ThomasSevestre commentedon Mar 18, 2024
@awh-tokyo I've sent you an email on awh@awh.org