Heroku, internal server error, Error R14 (Memory quota exceeded)

Viewed 1185

I have a FastAPI app on heroku, it was working fine but now I get Internal Server Error when I open the app, I checked the logs and I found this

2020-06-25T09:18:54.922877+00:00 app[web.1]: [2020-06-25 09:18:54 +0000] [10] [ERROR] Exception in ASGI application
2020-06-25T09:18:54.922878+00:00 app[web.1]: Traceback (most recent call last):
2020-06-25T09:18:54.922879+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/uvicorn/protocols/http/httptools_impl.py", line 375, in run_asgi
2020-06-25T09:18:54.922880+00:00 app[web.1]:     result = await app(self.scope, self.receive, self.send)
2020-06-25T09:18:54.922880+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/applications.py", line 133, in __call__
2020-06-25T09:18:54.922881+00:00 app[web.1]:     await self.error_middleware(scope, receive, send)
2020-06-25T09:18:54.922881+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/middleware/errors.py", line 177, in __call__
2020-06-25T09:18:54.922882+00:00 app[web.1]:     raise exc from None
2020-06-25T09:18:54.922882+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/middleware/errors.py", line 155, in __call__
2020-06-25T09:18:54.922883+00:00 app[web.1]:     await self.app(scope, receive, _send)
2020-06-25T09:18:54.922883+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/exceptions.py", line 73, in __call__
2020-06-25T09:18:54.922883+00:00 app[web.1]:     raise exc from None
2020-06-25T09:18:54.922884+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/exceptions.py", line 62, in __call__
2020-06-25T09:18:54.922884+00:00 app[web.1]:     await self.app(scope, receive, sender)
2020-06-25T09:18:54.922884+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/routing.py", line 590, in __call__
2020-06-25T09:18:54.922885+00:00 app[web.1]:     await route(scope, receive, send)
2020-06-25T09:18:54.922885+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/routing.py", line 208, in __call__
2020-06-25T09:18:54.922885+00:00 app[web.1]:     await self.app(scope, receive, send)
2020-06-25T09:18:54.922888+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/routing.py", line 41, in app
2020-06-25T09:18:54.922888+00:00 app[web.1]:     response = await func(request)
2020-06-25T09:18:54.922889+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/fastapi/routing.py", line 113, in app
2020-06-25T09:18:54.922889+00:00 app[web.1]:     raw_response = await run_in_threadpool(dependant.call, **values)
2020-06-25T09:18:54.922889+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/starlette/concurrency.py", line 25, in run_in_threadpool
2020-06-25T09:18:54.922890+00:00 app[web.1]:     return await loop.run_in_executor(None, func, *args)
2020-06-25T09:18:54.922890+00:00 app[web.1]:   File "uvloop/loop.pyx", line 2658, in uvloop.loop.Loop.run_in_executor
2020-06-25T09:18:54.922891+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/concurrent/futures/thread.py", line 123, in submit
2020-06-25T09:18:54.922891+00:00 app[web.1]:     self._adjust_thread_count()
2020-06-25T09:18:54.922891+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/concurrent/futures/thread.py", line 142, in _adjust_thread_count
2020-06-25T09:18:54.922892+00:00 app[web.1]:     t.start()
2020-06-25T09:18:54.922893+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/threading.py", line 846, in start
2020-06-25T09:18:54.922893+00:00 app[web.1]:     _start_new_thread(self._bootstrap, ())
2020-06-25T09:18:54.923075+00:00 app[web.1]: RuntimeError: can't start new thread
2020-06-25T09:18:55.285447+00:00 heroku[web.1]: Process running mem=805M(157.1%)
2020-06-25T09:18:55.287435+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2020-06-25T09:19:15.525510+00:00 heroku[web.1]: Process running mem=805M(157.1%)
2020-06-25T09:19:15.527704+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2020-06-25T09:19:35.447648+00:00 heroku[web.1]: Process running mem=805M(157.1%)
2020-06-25T09:19:35.450563+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)

I am not an expert in back end so I don't know what these errors mean, and this is the first time this error happened It was working normally for more than a month, just for testing, but if glad I found this error now not in production. I use the free tier here. If I upgraded to hobby will I face the same issue? and where the issue coming from anyway?

2 Answers

The RAM usage of your application has exceeded the available quota; since you are using the free tier, the memory quota is 512 MB. If you have a look at the log, the second line from the bottom says mem=805M. No, upgrading to Hobby will not resolve the issue, as it also offers 512 MB memory quota.

You can refer to this link for more details.

I fixed it by reducing the number of workers from 4 to 2

Related