I recently ran into a memory issue with my Vapor running on Heroku.
What happened:
I used Postman to repeatedly send POST requests to my app (basically simulating a long-running scheduled task). I run it for almost 24 hours. At first everything worked fine, but eventually Heroku reported that the dyno memory usage was too high.
Looking back, I realized a few things:
- Route timeout was set to 120 seconds.
- Heroku cut off requests at around 30 seconds.
- Some requests likely got terminated by Heroku before my app finished processing them.
My guess is that when Heroku cancels the request, my async tasks may still continue running, and memory doesn’t get freed as I expected.
I’m now planning to:
- Reduce timeout to 30 seconds to match Heroku.
- Explicitly cancel long-running tasks when a request fails.
My question is:
Is there anything else I should be aware of when running Vapor to prevent memory growth under heavy or long-running load?
I’m trying to understand whether this is mainly a task cancellation issue, or if there are other common pitfalls related to memory management in Vapor + Fluent.
Any advice would be greatly appreciated.
Thanks!
!