Hi everyone,
I am working through a persistent issue where Nest’s MongooseModule allows more connections to be created than what is passed the into the MongooseModuleOption’s maxPoolSize property. For example, a single Firebase function instance will open 200+ connections despite having a maxPoolSize of 25. This issue occurs when the app is deployed on a GCP Firebase cloud function. Locally, the number of connections are exactly as one would expect (up to 5-10 on concurrent db calls). For context, the NestJs app in question is a backend API for a web app.
Here are some of the things I tried:
• To diagnose the issue, I set the minimum and maximum number of cloud functions to “1”. This confirms that a single instance is creating more connections than it should.
• Based on answers to other Discord/StackOverflow posts that discussed similar issues, I implemented a durable data source provider that uses a random UUID to uniquely defined each Firebase function instance. With a Scope.DEFAULT scope, it did not seem to have an impact on the excessive connections… When using Scope.REQUEST The issue was made significantly worse (1000+ connections).
• Based on related research, I removed all concurrent database calls from all services, and removed all concurrent requests from the frontend. The rationale was that the number of connections could potentially exceed the set limit if there are multiple synchronous calls to the database.
Has anyone run into this type of issue before? Based on existing threads, it sounds like using a durable provider is the silver bullet… However, since we aren’t using multi-tenancy or a micro-service architecture, I don’t fully understand how this should be implement nor how it achieves anything more favorable than the default behavior of Nest.
I am posting code examples in a subsequent comment since I hit the 2,000 character cap.
Thank you in advance for any help or input.