Forums

502 Bad Gateway resulting from Segmentation Fault

In short, I intermittently get 502 errors while using some api calls on my site. b/c it seems to happen about 10% of the time for my ajax calls, I simply do the whole 'ignore it and try again' with the call and eventually it'll work. But because this is a bit of an integral part of the customers UI, I would obviously like to resolve this problem.

I've seen in some other online searches that it may be something to do with the version of uWSGI or something of that sort, but I'm certainly not adept enough to know enough about that sort of stuff. I've tried everything under the sun on my side, but whenever my api calls actually go through, everything works fine, and I can't even replicate it with certainty through an exact action.. it just happens randomly.

Looking at the Segmentation Fault, it only references python3.6 files so I don't 'think' it's on my side, but I could be mistaken. My site merely a site that queries a database and outputs the results to screen for the most part. Feel free to look at my site if you wish. The easiest place to replicate the error is within aznstifler.pythonanywhere.com/writing/ and just using the infinite scroll or clicking on side menu buttons and it'll happen after a few clicks.

Thanks in advance

A segfault from Python usually means that you're using a version in your virtualenv that is different to the one that is being used by uwsgi. Have you changed your system image? If you have, then you need to rebuild your virtualenv.

I haven't been using a virtualenv at all on this site. Is it recommended? I just installed all of the libraries I needed with pip3.6 etc etc and everything is working fine otherwise but if it'll get rid of the seg faults, I'm down to try anything.

Ok. Could you show us the exception traceback?

Oddly, it's not happening right now, but here's the error from the logs when I was getting it quite frequently, which prompted my post.

!!! uWSGI process 232 got Segmentation Fault !!! 2022-06-10 21:23:10 *** backtrace of 232 ***#012aznstifler aznstifler.pythonanywhere.com uWSGI worker 2(uwsgi_backtrace+0x2c) [0x46529c]#012aznstifler aznstifler.pythonanywhere.com uWSGI worker 2(uwsgi_segfault+0x21) [0x465661]#012/lib/x86_64-linux-gnu/libc.so.6(+0x36cb0) [0x7fc27363ecb0]#012/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0xc29a0) [0x7fc2723929a0]#012/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(PyDict_GetItem+0xc6) [0x7fc272393986]#012/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyObject_GenericGetAttrWithDict+0xcc) [0x7fc2723a519c]#012/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x187f) [0x7fc27243d63f]#012/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x16b1fe) [0x7fc27243b1fe]#012/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x16b512) [0x7fc27243b512]#012/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x2f3c) [0x7fc27243ecfc]#012/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x16a890) [0x7fc27243a890]#012/u

oh the errors are now back with a vengeance since I did a site reload with the web apps button.

I see you are running on old system image, that does not look like the reason for that failure, but upgrading may be the good opportunity to refresh your envirnonment in general, so it may help.

I just changed the system image to glastonbury (since my own pc's environment is in python 3.10 anyway), and I haven't gotten any of the gateway errors yet. Will keep you posted if they return, but I hope that was the issue.

Thanks for letting us know, and -- sure -- keep us updated!