Forums

502 Bad Gateway Error

I've been getting a 502 Bad Gateway Error for the last 10 minutes or so - is this something I could have caused or is it a server problem?

Looks like a server problem, we have a temporary fix in place and are working on a full one.

Thanks Giles!

Should all be sorted now. We're keeping a close eye on it...

Looks good to me!

hi im having this same problem right now

I am also having the same problem again.

We had a problem on one of our web servers a moment ago, everything should be fine now. There seems to be unusual load on the system, not quite DDoS levels but something's up. Investigating.

Thanks Giles!

Hi Giles - The bad gateway error is now gone, but I'm getting an Unhandled Exception error now. When I look at the erorr log it says OSError: [Errno 2] No such file or directory

I just wanted to check if this was something on pa's end as I haven't seen an error like this before. No need to trouble shoot if it's on my end, but just wanted to post in case it wasn't.

Am getting OSError as well !!

Here as well.

Am getting 502 Bad Gateway Error...

Working for me now

Sorry about that, and for the slow response; we had another glitch last night. Hansel and I were logged in and fixed it but we missed this forum thread, otherwise we'd have updated you sooner. We've worked out what the problem was and fixed it.

(Background: it's related to IO. Basically, one web app on one server went completely crazy and was eating up all of the IO for the whole machine. It wasn't the fault of the app's developer -- more a weird pathological case where trying to write to a disk when your quota is all used up starts grabbing all of the available IO bandwidth and blocks other processes. Hopefully our recent Ubuntu upgrade will make it easier for us to isolate stuff so that future incidents like this only affect the person who's hit their disk quota limit.)

I am also getting a 502 Bad Gateway Error

Hi Gimi, I think in this case you might not be providing a proper wsgi application. Do you want to post the code from your wsgi.py file or the error message in your log?

Hi today it work again for a while, but it shows again the 502 error.

the code from my wsgi.py is:

This file contains the WSGI configuration required to serve up your

web application at http://gimi.pythonanywhere.com/

It works by setting the variable 'application' to a WSGI handler of some

description.

The below has been auto-generated for your Django project

import os import sys

add your project directory to the sys.path

project_home = u'/home/gimi/Dropbox/gimi' if project_home not in sys.path: sys.path.append(project_home)

set environment variable to tell django where your settings.py is

os.environ['DJANGO_SETTINGS_MODULE'] = 'gimi.settings'

serve django via WSGI

import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()


and the in error.log, the last entry is 2013-07-29 12:05:42,002 :/usr/local/lib/python2.7/dist-packages/matplotlib/nxutils.py:48: MatplotlibDeprecationWarning: nxutils is deprecated. Use matplotlib.path.Path.contains_points instead. 2013-07-29 12:05:42,003 : mplDeprecation)

thanks!

Hi gimi,

A simple reload of your webapp was enough to get it working again. When you are making changes to the code base, including moving folders around. You might end up really confusing the web server processes that are running your application. Always try a reload.

Thanks! although when I make a change in a file (like views.py for example) I always reload the webapp, to apply the changes. It's after reloading that the error appears I'll try to reload again next time!

Having had a look at what you are doing I think the problem is that you are using Dropbox to serve your webapp. Dropbox isn't that reliable for syncing. If you try and reload the webapp while Dropbox is syncing something and the folder doesn't exist then you will have weird problems. I would recommend using something like git to sync changes...

I'm getting 502 off and on all afternoon. I figure some problem or other in the system - external to my app - is the cause.

I'm just wondering if you have an estimate for when the system will steady out? I'm trying to test software today...

The current system sometimes returns a 502 if you hit your web app immediately after reloading it. It takes a few seconds for the web app to restart after a reload. If you wait a few seconds and refresh the page, it should work. Is this the behaviour you're seeing?

"seconds"?

Hmmm.. I saw 3 minutes, and I'm not 100% sure we just reloaded or not.. One tester said 10 minutes - unverified.

3 min is definitely not just the reload pause.

Our web hosting is much less stable than we'd like and we're working hard on a fix right now. We're hoping to have it in testing by the end of the week and then deployed as soon as we've ironed out the kinks.

I had a similar 502 -- Bad Gateway problem this morning. Waiting a few minutes seemed to do the trick.

Do you happen to remember what time of day it was? We have what we hope will be a big fix for this kind of thing just going through our integration testing system at the moment; if the problem you saw was shortly before midday then it might be a good indication that the problem will be fixed by that change.

Giles -- Yes, I believe the timing lines up. Here's hoping!

Great, thanks for confirming!

I am still getting 502 errors. I have noticed a possible pattern.

As part of my testing I do this to activate any changes:

  • save files
  • Press RELOAD
  • Update error log, scroll to the bottom so new errors are more obvious
  • Switch to open tab in my application, and test.

I noticed what looks like a pattern, although I cannot explain it.

That is, after I RELOAD my web ap, the end of my error log has the same three items and a blank line.

I have noticed that when I get the 502 error, those lines are missing. And if I press RELOAD again, get those lines, the error is gone.

Is it possible that the "reload" task is failing or timing out? Leaving me in crippled state??

I think it's more likely that it is a race condition between the files actually being saved to disk and the reload occurring. i.e files are in a half saved state and broken, your webapp starts up with bad code, you hit reload, it reloads again with good code. File server performance is something we are working on right now...

What time delay between "save" and "reload" would you suggest?

Well, it depends. When I am working on PythonAnywhere I typically use an editor (vim) inside a Bash console. Vim blocks until the file has been saved properly so I know exactly when I can start running my tests. This can sometimes take a couple of seconds when the system is under heavy load. When using the browser based editor I would allow for those two seconds plus take into account the time it takes for an http request to be sent to the server.

It doesn't sound like those sort of time scales are really what you are talking about though. I know some other users were having problems because they were actually serving their site out of their Dropbox folder. Which can take minutes to sync. I advised them to start using git to push and pull their change from the local drive to our servers.

OK, the problem where there some apps got 502 errors in mid-morning should now be fixed.

Any other 502s are well worth reporting, though. It's a generic error page that you get when something's wrong with your site and it can't even start running to a level where it can display its own error page, which can happen if there are problems with your code (completely broken imports, for example) but can also be caused by problems on our side.

I am getting the 504 Gateway Time-out error. At about the same time yesterday, I got this error. Can you please look into it?

Just to clarify, the page was launching fine about 30 mins back. There were no code/db changes after that.

Its fine now. Thanks. Do we know why this is happening?

It was a rogue backup process, it caused some disk I/O issues for about 20-30 minutes. Things are back to normal now.

For info, we post status updates on twitter: https://twitter.com/pythonanywhere

Not fixed. I'm getting the 502 Bad Gateway error right now.

Weird. It looks like it just needed a reload. I'll try to see if I can work out what was going on.

New 502 over here now.

Hi meningo, did you try a reload? I just logged onto the server your app was running on and manually reloaded it for you and it's working now.

Tried! However, Now it works again :) thanks

hi there, just for anyone else coming across this thread from a search, we have a page of tips on dealing with 502 bad gateway errors on pythonanywhere now!