Forums

502-backend Error very inconsistently

Hi, my site (flannelfy.net) has recently started resulting in a 502-backend error somewhat frequently. However, I cannot reliably replicate the error; sometimes it will happen on my first attempt at using the site and sometimes I'll have to try multiple times before getting the error. My site uses the Spotify and Last.fm APIs, and the error can occur in either one; refreshing, as the error page suggests, sometimes (but not always) fixes the issue. I thought it might be an issue with expiring API tokens, which may still be partially the case with the Spotify functionality, but Last.fm doesn't rely on tokens that can expire and the same problem arises.

I've made sure to try it while the site wasn't in the process of reloading, and my error log unfortunately stopped updating a few hours ago as of writing this; the only suspicious message in my server log is: "corrupted size vs. prev_size", which seems to be something I have no direct influence over, though I'm not certain.

A link to the sourse code is given at the bottom of my home page and I'm happy to provide any additional information; any help is greatly appreciated. At the very least, I would like to be able to catch the error and exit gracefully with a custom error page, but I can't reliably find the source of the issue.

Maybe add some extra logging to your code to see what is going on. You will see where in your code things happen and if it is something we can help with or is it related to external system.

I believe I've resolved the issue, so hopefully this can be useful if anyone has a similar problem in the future. I also have a quick question about Batteries Included.

My server log sometimes included the error "free(): invalid size", which other forum posts indicated is caused by issues with dependencies. I recently removed dependencies from my requirements.txt that are part of Batteries Included in order to save disk space, but adding them back seems to have fixed it, so there must have been a compatibility issue.

Regarding Batteries Included, I may want to reduce the number of dependencies installed in my venv, since it takes up ~20% of my disk and almost all of them are in BA. Are the versions of everything in BA compatible with each other, or could there be instances where I'd have to install a specific version of one or the other in my venv? Is there any built in way to see which packages I'd be safe to remove from my requirements without causing errors, or would I just have to check the BA versions of each one by one?

I think you could create a venv with --system-site-packages flag, then create your requirements (minus the packages available in Batteries Included) and then run pip check. But, generally, you'd need to experiment and see if things work as expected.