2

I have a Python application served via CherryPy's WSGI server, receiving requests from Nginx. It's hosted on a Windows Server 2003 box, and there are only a few users accessing it.

Sometimes, requests to a specific resource fail almost instantly with a 502 Bad Gateway on Firefox. I've tried to reproduce the problem on other browsers, without success.

The application is started like this:

paths = { "/resource": resource_func }
dispatcher = wsgiserver.WSGIPathInfoDispatcher(paths)
server = wsgiserver.CherryPyWSGIServer(("127.0.0.1", 9191), dispatcher)
server.start()

The nginx server is forwarding requests to CherryPy via proxy_pass:

location / {
    proxy_pass         http://127.0.0.1:9191/;
    proxy_redirect     off;

    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}

The requests are sent via jQuery.ajax method:

$.ajax(requestURI).done(myRequestCallback);

If I run Firebug, then open nginx error log when a 502 occurs, I see the following error:

(time): *92 WSASend() failed (10054: An existing connection was forcibly closed by the remote host) while sending request to upstream, client: xxx.xxx.xxx.xxx, server: localhost, request: "GET /resource?params=VALUES&_=1371674388573 HTTP/1.1", upstream: "http://127.0.0.1:9191/resource?params=VALUES&_=1371674388573", host: "xxx.xxx.xxx.xxx:9080", referrer: "http://172.27.129.112:9080/myAppPage.html"

... where xxx.xxx.xxx.xxx is the IP from which I'm testing the application, and nginx is listening to 9080.

The failing requests do not show up in our app's log file, and the same resource and params are valid (a request does not fail on every attempt).

I've even added the following lines to my nginx.conf file (then restarted both servers) to try to fix the problem, but it didn't seem to make ay difference:

proxy_buffers 8 16k;
proxy_buffer_size 32k;

The versions are:

  • Firefox 21
  • Python 2.7.5
  • nginx 1.2.0
  • CherryPy 3.2.2

What could be causing the error?

Fernando
  • 21
  • 4

1 Answers1

0

When I've seen this (not with CherryPy, but with Gunicorn/others), it's been because the server is restarting and Nginx can't connect to it. Is anything else happening on the server which might be causing CherryPy to restart?

Paul
  • 791
  • 5
  • 8
  • I start the WSGI server from a script, and unless CherryPy restarts any of its components internally, it is not stopped by the time I see the error. What I found intriguing is that I could only reproduce it on Firefox... I've also looked at [this question](http://stackoverflow.com/questions/3704626/nginx-502-bad-gateway-error-only-in-firefox) but it's not the same error on the log. – Fernando Jun 20 '13 at 12:43