fork_reactor causes unbind to be called twice

23 views
Skip to first unread message

Tasos Laskos

unread,
May 3, 2013, 10:06:36 PM5/3/13
to eventm...@googlegroups.com
Hey folks,

I'm experiencing some strange bahavior when calling EM.fork_reactor,
from what I can tell, it causes unbind to be called twice.

Under my more complex real-world application this causes some mayhem
because it triggers my retry-on-failure mechanism and results in messages
being sent multiple times.

I've pasted a sample client and server, what I'm seeing at the server's
side is the message in unbind to be shown twice when the fork call
is left in place and shown once when the call is removed.

I'm using EventMachine 1.0.3.

Any ideas?

----------------------------------------------------


Client:
-------------
require 'eventmachine'

module Client
def connection_completed
puts "Client - connected"
send_data 'Request'
end

def unbind( reason )
puts "Client - disconnected"
fail if !@done
@status = :closed
end

def receive_data( data )
#p data
ensure
@done = true
close_connection
end
end

EM.run do
EM.connect( 'localhost', 5000, Client )
end

----------------------------------------------------

Server:
-------------
require 'eventmachine'

module Server
def connection_completed
puts "Server - connected"
end

def receive_data( data )
p data
send_data 'Response'

EM.fork_reactor do

end
end

def unbind
puts "Server - disconnected"
end
end

EM.run do
::EM.start_server( 'localhost', 5000, Server )
end

Tasos Laskos

unread,
May 4, 2013, 9:20:59 PM5/4/13
to eventm...@googlegroups.com
I found something that works:

EM.schedule { Kernel.fork { stuff } }

The above seems to do the trick (so far at least) both in the
simple sample code I included in my first e-mail and in my real-world
system.

Maybe include a notice in the docs about that sort of thing?

Cheers
Reply all
Reply to author
Forward
0 new messages