hemant
2007-Feb-10 17:52 UTC
[Eventmachine-talk] EventMachine not raising exceptions properly
Well, EventMachine seem to screw up on raising exceptions. In my particular case, I wrote a class called Common(in a file common.rb), which can be used as both client and server and was using buftok and forgot to do a require on buftok, and all EventMachine would tell me about this error is: A client connected" /usr/local/lib/ruby/site_ruby/1.8/eventmachine.rb:801:in `event_callback'': EventMachine::ConnectionNotBound (EventMachine::ConnectionNotBound) from /usr/local/lib/ruby/site_ruby/1.8/eventmachine.rb:209:in `release_machine'' from /usr/local/lib/ruby/site_ruby/1.8/eventmachine.rb:209:in `run'' from em_slave.rb:14:in `initialize'' from em_slave.rb:31:in `new'' from em_slave.rb:31 Of course, it took sometime to figure out the exact problem because of EM ate the exception. BTW, i am experimenting with making EM and drb work together using Slave library. -- gnufied ----------- There was only one Road; that it was like a great river: its springs were at every doorstep, and every path was its tributary.
Francis Cianfrocca
2007-Feb-10 18:22 UTC
[Eventmachine-talk] EventMachine not raising exceptions properly
On 2/10/07, hemant <gethemant at gmail.com> wrote:> > Well, EventMachine seem to screw up on raising exceptions. In my > particular case, I wrote a class called Common(in a file common.rb), > > which can be used as both client and server and was using buftok and > forgot to do a require on buftok, and all EventMachine would tell me > about this error is: > > A client connected" > /usr/local/lib/ruby/site_ruby/1.8/eventmachine.rb:801:in > `event_callback'': EventMachine::ConnectionNotBound > (EventMachine::ConnectionNotBound) > from /usr/local/lib/ruby/site_ruby/1.8/eventmachine.rb:209:in > `release_machine'' > from /usr/local/lib/ruby/site_ruby/1.8/eventmachine.rb:209:in > `run'' > from em_slave.rb:14:in `initialize'' > from em_slave.rb:31:in `new'' > from em_slave.rb:31 > > Of course, it took sometime to figure out the exact problem because of > EM ate the exception. > > BTW, i am experimenting with making EM and drb work together using > Slave library.Hi Hemant. Were you able to find the begin statement in EM that ate the exception? (I''m guessing it was a NameError or a LoadError) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20070210/c0f2b668/attachment.html
hemant
2007-Feb-10 19:10 UTC
[Eventmachine-talk] EventMachine not raising exceptions properly
On 2/11/07, Francis Cianfrocca <garbagecat10 at gmail.com> wrote:> On 2/10/07, hemant <gethemant at gmail.com> wrote: > > Well, EventMachine seem to screw up on raising exceptions. In my > > particular case, I wrote a class called Common(in a file common.rb), > > > > which can be used as both client and server and was using buftok and > > forgot to do a require on buftok, and all EventMachine would tell me > > about this error is: > > > > A client connected" > > /usr/local/lib/ruby/site_ruby/1.8/eventmachine.rb:801:in > > `event_callback'': EventMachine::ConnectionNotBound > > (EventMachine::ConnectionNotBound) > > from > /usr/local/lib/ruby/site_ruby/1.8/eventmachine.rb:209:in > > `release_machine'' > > from > /usr/local/lib/ruby/site_ruby/1.8/eventmachine.rb:209:in > `run'' > > from em_slave.rb:14:in `initialize'' > > from em_slave.rb:31:in `new'' > > from em_slave.rb:31 > > > > Of course, it took sometime to figure out the exact problem because of > > EM ate the exception. > > > > BTW, i am experimenting with making EM and drb work together using > > Slave library. > > > Hi Hemant. Were you able to find the begin statement in EM that ate the > exception? (I''m guessing it was a NameError or a LoadError) > >Yes, It was a NameError and the problem is because of these lines in EM: def EventMachine::event_callback conn_binding, opcode, data case opcode when ConnectionData c = @conns[conn_binding] or raise ConnectionNotBound c.receive_data data when ConnectionUnbound if c = @conns.delete( conn_binding ) c.unbind elsif c = @acceptors.delete( conn_binding ) # no-op else raise ConnectionNotBound end As, we can see, since EM catches all exceptions in the or block and re-raises them as ConnectionUnbound exception, making things a bit difficult. def receive_data data @tokenizer.extract(data).each do |_data| # process it end end Did I answer your question Francis? or you asked something else? btw, i did manage to fork drb processes using slave library and handle time taking jobs as seperate processes, rather than clogging the main EM loop. child process, can also have their own EM loop using EventMachine.run and its working quite well. -- gnufied ----------- There was only one Road; that it was like a great river: its springs were at every doorstep, and every path was its tributary.
Francis Cianfrocca
2007-Feb-10 19:45 UTC
[Eventmachine-talk] EventMachine not raising exceptions properly
On 2/10/07, hemant <gethemant at gmail.com> wrote:> > > Yes, It was a NameError and the problem is because of these lines in EM: > > > def EventMachine::event_callback conn_binding, opcode, data > case opcode > when ConnectionData > c = @conns[conn_binding] or raise ConnectionNotBound > c.receive_data data > when ConnectionUnbound > if c = @conns.delete( conn_binding ) > c.unbind > elsif c = @acceptors.delete( conn_binding ) > # no-op > else > raise ConnectionNotBound > end > > > As, we can see, since EM catches all exceptions in the or block and > re-raises them as ConnectionUnbound exception, making things a bit > difficult. > > def receive_data data > @tokenizer.extract (data).each do |_data| > # process it > end > endI''m looking for the "begin" statement that catches the NameError that evidently gets thrown out of your receive_data function. I wonder if it''s the one in EventMachine::run (line 206 in the latest version of eventmachine.rb). Can you try adding a rescue NameError clause to that function, just to see if it catches your error? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/eventmachine-talk/attachments/20070210/45415962/attachment.html
hemant
2007-Feb-11 05:41 UTC
[Eventmachine-talk] EventMachine not raising exceptions properly
On 2/11/07, Francis Cianfrocca <garbagecat10 at gmail.com> wrote:> On 2/10/07, hemant <gethemant at gmail.com> wrote: > > > > > Yes, It was a NameError and the problem is because of these lines in EM: > > > > > > def EventMachine::event_callback conn_binding, opcode, data > > case opcode > > when ConnectionData > > c = @conns[conn_binding] or raise ConnectionNotBound > > c.receive_data data > > when ConnectionUnbound > > if c = @conns.delete( conn_binding ) > > c.unbind > > elsif c = @acceptors.delete( conn_binding ) > > # no-op > > else > > raise ConnectionNotBound > > end > > > > > > As, we can see, since EM catches all exceptions in the or block and > > re-raises them as ConnectionUnbound exception, making things a bit > > difficult. > > > > def receive_data data > > @tokenizer.extract (data).each do |_data| > > # process it > > end > > end > > > I''m looking for the "begin" statement that catches the NameError that > evidently gets thrown out of your receive_data function. I wonder if it''s > the one in EventMachine::run (line 206 in the latest version of > eventmachine.rb). Can you try adding a rescue NameError clause to that > function, just to see if it catches your error?def EventMachine::run &block begin initialize_event_machine block and add_timer 0, block run_machine ensure release_machine end end I guess, above is the function that is catching that exception. -- gnufied ----------- There was only one Road; that it was like a great river: its springs were at every doorstep, and every path was its tributary. http://people.inxsasia.com/~hemant