Mongrel, Nginx, and AJAX not working

Under Apache / FastCGI, the following request is perfectly fine (as
pulled
from the browser’s View Source):

new
Ajax.Request(‘http://server/portals?editable=true&update=portal_list_wrapper’,
{asynchronous:true, evalScripts:true, method:‘get’})

However, under my new setup of Nginx and Mongrels, the call never
returns. I
get the proper log in production.log, stuff happens, and my browser just
sits there twiddling it’s thumbs, never getting what it wants back
(note:
the update is meant to be part of the GET string).

Has anyone else had a problem with this kind of setup? It feels that
AJAX
responses are getting stopped by Nginx but I can’t find anything out
about
this.

Thanks

Jason

I know this isn’t the answer you’re looking for, but I ran into issues
like this at least 3 times with lighttpd which is why I switched to
nginx/mongrel. Each time I had a problem, firebug was essential in
figuring out the problem… maybe take a look at the output from
firebug and see if it helps…

-Vince

On 7/24/07, Jason R. [email protected] wrote:

the update is meant to be part of the GET string).


support independent business – http://www.buyindie.net/

Yeah, I’ve been watching Firebug, the request just spins until it times
out.
Getting back into the server works no problem, but there’s nothing
coming
back to my browser.

Thanks though. Interesting that you had this same problem with lighty.

Jason

On Tue, 24 Jul 2007 13:10:42 -0400
“Jason R.” [email protected] wrote:

Under Apache / FastCGI, the following request is perfectly fine (as pulled
from the browser’s View Source):

new Ajax.Request(‘http://server/portals?editable=true&update=portal_list_wrapper’,
{asynchronous:true, evalScripts:true, method:‘get’})

What happens when you do & rather than & ?


Zed A. Shaw

I had a very similar thing happen a few days ago and found a solution
for my problem last night. That was Ajax request and firebug was
showing the request as spinning and spinning…

The code was using Ajax.Request with a post (not a get), and worked
fine just with mongrel, but through nginx, it was taking 120s to get
back to that Complete state (and, although I’m not sure why, the
reason it was taking 120s was probably that another Ajax request was
being fired up every 120s).

The code responding to the request couldn’t be simpler:

 render :text => @mailbox.count.unseen

unseen happens to return an integer, not a string. And when trying
with a string it worked

 render :text => "1234567890"

So just for a moment I thought it was the size of the request, but
even a 1 byte string did not make any difference and still worked. So
just changing that line to:

 render :text => @mailbox.count.unseen.to_s

fixed it for me. I have not attempted to figure out further what was
happening, but my best theory is that the mime type returned by rails
(mongrel?) may be different and nginx (or the browser?) is waiting
for more to send the response back).

Not sure the same thing is happening in your case, but that may be
worth looking more closely at the mime type.

Cheers,
Pascal.

http://blog.nanorails.com

Follow-up # 2

Ignore previous post, I’m still stuck, though I know what’s wrong now.
This
is a site migration so traffic already exists to the url. I put up the
site
on the new box under a different url to see if it works and sure enough,
it
was snappy and perfect. Thinking all was good, I changed the DNS entry
for
the real URL and bam, back to a broken site.

So this is a load balancing issue then, or at least that’s what it looks
like. I now know the whole stack works, but under a site that gets
constant
but in no ways heavy load, requests responses get lost. Literally.

As for the mime type, I’ll definitely look into that but all of my
responses
are RJS and thus strings.

Ug…

Jason

Follow-up:

I honestly do not know what I did, but it’s working now. I did install
swiftiply to use it’s evented_mongrel handler, so there might be
something
there that fixed the problem but I’m not sure.

Thanks for all of your suggestions.

Jason

So I just decided to bypass the problem and move to a different URL. Not
going to deal with it if I can just get around it.

Jason