dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.71k stars 164 forks source link

Global state - New connections outside handler #251

Closed syedahmedhaidershah closed 1 year ago

syedahmedhaidershah commented 1 year ago

Hi, I noticed this issue while using Mongoose.

PS my issue IS NOT related to Mongoose. While using serverlessHTTP, my Mongoose connection initialized outside the handler, though for some reason when I use it inside the handler creates a new connection.

Somehow ServerlessHTTP creates a new namespace for the function state.

It destroys the Singleton pattern of Mongoose.

REF: https://www.mongodb.com/docs/atlas/manage-connections-aws-lambda/#std-label-lambda-aws-example

dougmoscrop commented 1 year ago

I think I understand what you're describing, but I don't believe serverless-http is causing this, it is a bug in your code or some kind of pooling behaviour on mongoose. If you share code, I can give a more specific response.

syedahmedhaidershah commented 1 year ago

Hey @dougmoscrop we looked into it deeper, popped up in our EC2 Auto-scaling groups too (where we are not even using serverless).

It is an issue in fact, an issue with Mongoose.

Closing this 😊 Thanks man