Occasional 502 Bad Gateway When Uploading

  • Posted February 6, 2015


I’m new to running and maintaining my own server.

I noticed that in my web app, uploading images at a fast speed (i.e. consecutively without waiting for the previous images to finish uploading) sometimes causes my web app to crash with a 502 Bad Gateway error.

Once I refresh the page after this error, everything is OK.

If I upload at normal speeds, everything is fine.

In development mode/localhost, pace of upload is never a problem.

Is this an app issue? Or a server issue? Is this caused by not having a powerful-enough server?

If this is caused by a weak server. How can I tell? Also how do I figure out what I need to upgrade Droplets to in order to prevent this issue?


In one of my logs, I’m seeing…

Out of memory: Kill process 20450 (node) score 184 or sacrifice child
Killed process 20528 (gm) total-vm:179208kB, anon-rss:117580kB, file-rss:0kB

Is it safe to assume that I need to upgrade my server to more Droplets?

Is there some way that I can estimate the right amount of Droplets to upgrade to?

You would need to read the logs of your webserver/application server so you can read the actual error, then at that point you can start determining what to do once you find out what is occuring.

The logs for nginx and apache are generally found under the /var/log directory.

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Thank you EpicCDN,

I’m actually using Node.JS and the app is a Meteor.JS app. And the uploads are happening via whatever way GraphicsMagick uses.

Could you please help me understand how to do these tasks?

  • How can I check “how many children” and “maxspareserver” are running?
  • How can I check top/htop memory I am consuming?

Also since the posting of this topic, I did upgrade. The problem happens slightly less but I it didn’t stop completely. I find that this happens especially more if I continuously upload images that are 7 to 14 mbs big at somewhat quick speeds.

If I do not wait for each upload to finish, this problem is particularly worse.

I think you need to change your php process settings, as you are using nginx I assume you are using php-fpm? check how many children, and max_spare_server are you running. You may need some tweaks.

also check with top/htop how much memory are you consuming in your droplet, is is near the top of it, you may need an upgrade, but also can be you have too many php processes running for your amount of ram available, so again you may need some tweaks there.