Help debugging 500 error on some json responses - nginx

I'm creating a django app in which I pass data via json from my server to the broswer to load new content as a user scrolls. Everything works fine on django's dev server on my laptop, but on the production server (still only used by a few tester users), certain items will consistently cause 500 errors. I believe it is because they are too large, but I don't know what setting to adjust to accomodate it.

The error from nginx access log (not very helpful):

[redacted IP] - - [23/May/2013:16:40:40 +0000] "POST /nextitems/VLPCQVAMGV/21/21/ HTTP/1.1" 500 2006 "http://[redacted domain].com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31"

For one of the items that works fine on my laptop, but fails on the server, the log from the django runserver is:

[23/May/2013 04:01:12] "POST /nextitems/U48ST0SB84/36/36/ HTTP/1.1" 200 25216

That size (25216 bytes) is relatively large for the json I'm trying to pass, which is why I think it fails on the server. I also have another method to pass the same item as html, which works on the server (indicating it's not a database problem, and seems to be specific to passing json).

I also looked at the uwsgi log and I see (for a different nextitems call that caused a 500):

[pid: 3390|app: 0|req: 461/918] [redacted IP] () {50 vars in 916 bytes} [Thu May 23 12:35:58 2013] POST /nextitems/VX5VEQEA6G/21/21/ => generated 1994 bytes in 37 msecs (HTTP/1.1 500) 3 headers in 121 bytes (1 switches on core 0)

which looks OK, but chrome shows me:

POST http://[redacted IP].com/nextitems/VX5VEQEA6G/21/21/ 500 (INTERNAL SERVER ERROR) 

Any ideas on how to fix this or how to further debug it? Thanks in advance!

8 Replies

I think you may wanna tweak clientmaxbody_size in nginx.conf. It's default to 1024 bytes, your 25216 bytes is way larger than that.

Here is the ref

http://wiki.nginx.org/HttpCoreModule#cl … _body_size">http://wiki.nginx.org/HttpCoreModule#clientmaxbody_size

Thanks for the reply. My understanding is that clientmaxbody_size is for size of the request TO the server (please correct me if I'm mistaken), but my issue is occuring when passing a json response FROM the server to the browser. The request to the server in this case is quite small.

Are you aware of a setting in nginx or elsewhere that would help send large json responses from the server?

If you set DEBUG=True in your settings.py, you should be getting a lot of not-JSON that will explain what happened; you can trap this in your browser's development tools.

You might also want to consider Sentry… it's either available as a standalone server, or as a paid service, and it is indispensable for app development.

hoopycat, I can't believe I didn't think to set debug to True on production (I've solved problems on the server that way before)… I figured out the error, which was the result of a standard output unicode problem. It's crazy the patterns you think you see when problems creep up. I'm still not sure why it didn't cause problems on the dev server, but the problem is resolved.

Thanks!

Oh, and it's always a Unicode encoding problem. :-)

Just a note for future use: instead of setting DEBUG=True on a production server this snippet should be a little more secure and let you do the same thing as a superuser: http://ericholscher.com/blog/2009/sep/5 … revisited/">http://ericholscher.com/blog/2009/sep/5/debugging-django-production-revisited/

That is good advice, thanks. I'll try that out.

I also just realized that my server had been emailing me the 500 debug info the entire time, but gmail was was filtering it as spam.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct