Forums

Flask API failing somewhat randomly

Hi... I've been designing a side project that calls a Flask API hosted here. It loads some big datasets (2 GB) and calls some libraries that sort/compute, makes a few external API calls, then returns a string. Often when I first make an API call from my frontend, it fails and the error log is:

DAMN ! worker 1 (pid: 47) died, killed by signal 9 :( trying respawn ...
Respawned uWSGI worker 1 (new pid: 50)
spawned 2 offload threads for uWSGI worker 1

This makes me think that there is too much memory being used. But subsequent API calls generally work fine, even with the exact same inputs passed in. It really just seems like the initial call fails ~85% of the time. And calls afterwards fail ~5% of the time.

The error that in my frontend console log is:

Access to fetch at 'https://MY_URL' from origin 'MY_OTHER_URL' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
MY_URL     Failed to load resource: net::ERR_FAILED
2.be3a3fac.js:7 TypeError: Failed to fetch
at window.fetch (start.44254355.js:1:1536)
at f (2.be3a3fac.js:7:3039)
at HTMLTextAreaElement.q (2.be3a3fac.js:7:3482)

But I've obviously added it to my CORS policy, and it works most of the time.

How can I better triangulate if it's actually a memory issue? This is my first time making a full stack app like this. The code def uses a lot of memory and was written to spin-up a project, not to be a production product, so I'd rather not rearch it to reduce memory if possible.

Memory limit is 3 GB. First hit to the web app after some time could take lot of time as it spins up.