-
Notifications
You must be signed in to change notification settings - Fork 65
Using it in forked / multithreaded env #103
Comments
Are you using |
Try to force passenger to never call fork(), e.G. into something of a testing/debugging mode. zeromq, the underlying library which is used to handle the messaging part, doesn't survive a fork() call. If it works that way you have to setup DCell in a "after_fork" hook or something similar. |
@digitalextremist The @Asmod4n good hint, I just managed to get first things working with this: # initializer
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
next unless forked
DCell.start id: 'sender', addr: 'tcp://127.0.0.1:9002'
end
end This worked now for the first five minutes, I'll report if it works longer after some testing. Thanks! |
After some time it appears that
So maybe I have to close an old connection before calling if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
next unless forked
DCell.stop if DCell.running? <--- something like this?
DCell.start id: 'sender', addr: 'tcp://127.0.0.1:9002'
end
end |
You would have to use a new port for each fork, and also a new name. |
Oh and since you are on localhost, you could also use "ipc:///path/to/a/unix.sock" for a little bit better performance and security. But be aware, when different forks bind to the same unix socket only the newest one will own the socket. |
So there'd be But what happens if the |
@doits if you are using master branch you don't have to specify port number and put |
I'm trying to use
DCell
in my rails app like the following:The node
client
is existing and implements the actor:xmpp
which has the methodsend_message
. When I start Rails in development mode (unicorn
webserver), everything works.DCell
connects to theclient
and calls the methodsend_message
on the existing actor:xmpp
.But when I use
passenger
as a web server, the lineDCell::Node['client'][:xmpp].send_message 'something'
hangs forever. In theclient
node I do not get any connection attempt (... Connected to sender
). I think this might be becausepassenger
is using multiple threads and forking. Is there any solution to this? How to useDCell
in a multithreaded environment?The text was updated successfully, but these errors were encountered: