Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twisted server crashes unexpectedly while running django

I am running a django application on twisted using the django-on-twisted scripts from this site.

All requests are served by an nginx server which reverse proxies relevant requests to twisted. I have a url setup for an API, which basically just receives get requests and does some processing on the get parameters before sending a response. However, when a specific client is hitting the api, the twisted server just shuts down. Pasted below is the Nginx log:

the.ip.of.client - - [21/Apr/2012:11:30:36 -0400] "GET /api/url/?get=params&more=params HTTP/1.1" 499 0 "-" "Java/1.6.0_24"

The twisted logs show nothing but twisted stops working at this point. By the error code 499, i am assuming that the client closed the connection unexpectedly, which I have no problem with. Whether the client receives the response or not is not important to me. Here is the relevant django view:

def api_url(request):
    if request.GET:
        get_param = request.GET.get('get', [''])[0]
        more_param = request.GET.get('more', [''])[0]
        #some processing here based on the get params
        return HttpResponse('OK')
    else:
        raise Http404

The request from the client is a valid request and does not affect the processing in an adverse way. I have tested it from the shell. When I tried it on the django development server, it crashed in the same way too without leaving any traces of receiving the request. Everything works perfectly well when testing it from the browser. Also, the twisted server works well for all the regular use cases. This is the first time I am facing an issue with it. Any help or pointers will be appreciated.

like image 873
tapan Avatar asked Apr 21 '12 16:04

tapan


2 Answers

There is no 499 http code in rfc. Nginx defines 499 code itself.

When a client sent a request, and closed the connection without waiting for the response, a 499 code occurs. If there're a lot of 499s in your access_log, it's mostly caused by the slow back-ends (too slow for your users to wait). You may have to optimize your website performance.

http://forum.nginx.org/read.php?2,213789,213794#msg-213794

like image 71
SanityIO Avatar answered Oct 30 '22 19:10

SanityIO


  • you say the problem is from a client hitting a particular url (reproducible?)
  • since it works for you with gunicorn but not django-on-twisted, either the script is not working properly or twisted.web2 is the issue.

please try $ sh init.sh yourdjangoproject stand.

you can also try to modify run.py to catch SystemExit:

import pdb
try:
   # __main__ stuff here.
except (KeyboardInterrupt, SystemExit):
   pdb.set_trace()
like image 1
dnozay Avatar answered Oct 30 '22 17:10

dnozay