"show_clients_for_channels" (Infinite loop)

3 views
Skip to first unread message

MacBoy

unread,
Nov 5, 2009, 4:46:59 AM11/5/09
to Juggernaut for Rails
Hi, I am new here. I am developing a chat room. The chat room shows a
list of online users. I use the :subscription_url
and :logout_connection_url to login and logout the chat room.

I use "show_clients_for_channels" to get the list of online users, but
sometimes the flash keep disconnect from the server and keep reconnect
but never success.

Base on my test, when the "show_clients_for_channels" command is
running, at that moment, a new flash client try to connect to the
juggernaut server, that new user will disconnect from the server and
trigger infinite retry. Below is a demo code:

def juggernaut_subscription
channel = params[:channel]
online_users = Juggernaut.show_clients_for_channels(channels).map{|
j| j["client_id"]}.uniq.compact
Juggernaut.send_to_channel("alert(#{online_users.join(',')})",
channel)
render :text => "", :status => 200
end

I tried to move the "how_clients_for_channels" to a AJAX call after
"juggernaut_subscription" action finish, it does not solve the problem
completely, just minimize the problem.

I am using this version http://github.com/maccman/juggernaut_plugin

Thanks, any idea?

Oleg Petukhov

unread,
Nov 23, 2009, 4:58:09 PM11/23/09
to Juggernaut for Rails


On 5 ноя, 12:46, MacBoy <mac4w...@gmail.com> wrote:
> Hi, I am new here. I am developing a chat room. The chat room shows a
> list of online users. I use the :subscription_url
> and :logout_connection_url to login and logout the chat room.
>
> I use "show_clients_for_channels" to get the list of online users, but
> sometimes the flash keep disconnect from the server and keep reconnect
> but never success.

I encountered the same problem recently. It seems to me that one
cannot
access juggernaut process while it is waiting for the response from
subscription_url. Thus, in your rails app you cannot get the user list
in
juggernaut_subscription handler (which I wanted to do also).

> I tried to move the "how_clients_for_channels" to a AJAX call after
> "juggernaut_subscription" action finish, it does not solve the problem
> completely, just minimize the problem.

I have no idea why a delayed request should make the same deadlock,
did you find out something?

MacBoy

unread,
Jan 19, 2010, 8:27:40 AM1/19/10
to Juggernaut for Rails
No, this problem is still appear in my local development server, but
seems it works in production (mongrel_cluster). Still no idea yet.

Noah Gibbs

unread,
Jan 19, 2010, 10:29:15 AM1/19/10
to juggernaut...@googlegroups.com
I'm pretty sure that juggernaut is single-threaded, with very simple flow of control.

Perhaps your server is only set up to handle a single connection at once, and the juggernaut request is getting queued behind the main HTTP request? That would explain why you're only seeing it in development -- a production server is pretty certainly configured to handle multiple requests at once.

--- On Tue, 1/19/10, MacBoy <mac4...@gmail.com> wrote:

> --
> You received this message because you are subscribed to the
> Google Groups "Juggernaut for Rails" group.
> To post to this group, send email to juggernaut...@googlegroups.com.
> To unsubscribe from this group, send email to
> juggernaut-for-r...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/juggernaut-for-rails?hl=en.
>
>
>



Marek Kowalski

unread,
Mar 1, 2010, 6:36:08 PM3/1/10
to Juggernaut for Rails
You are right, it is basen on eventmachine. The problem is it uses
Net::Http::Post class to contact rails application. This is blocking
synchronous action. So if you have only one instance of applicaton
server it will always result in deadlock. If you really want to be
able to contact juggernaut in subscribe/logout/disconnect action you
have to hack juggernaut code a little. Instead of using blocking post
you should use eventmachine api:

http = EventMachine::Protocols::HttpClient.request(
:host => uri.host,
:port => uri.port,
:request => uri.path,
:content => params,
:contenttype => "application/x-www-form-urlencoded",
:verb => "POST"
)

You also have to define a http.callback and errback to play nice with
subscribe action.

Hope this helps.

Best regards
Marek Kowalski

On 19 Sty, 16:29, Noah Gibbs <noah_gi...@yahoo.com> wrote:
>   I'm pretty sure that juggernaut is single-threaded, with very simple flow of control.
>
>   Perhaps your server is only set up to handle a single connection at once, and the juggernaut request is getting queued behind the main HTTP request?  That would explain why you're only seeing it in development -- a production server is pretty certainly configured to handle multiple requests at once.
>

> --- On Tue, 1/19/10, MacBoy <mac4w...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages