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?