-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any CRUD statement execution may have rare hang case #9492
Comments
Issue may be related with #9179 |
@SinLok just to confirm, have you tried waiting for 10 seconds? Also, try reducing |
I tried to set AWS Lambda timeout to 900s and added 2 For |
Using |
Try reducing conn = mongoose.createConnection(uri, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 1000, // <-- Add this
heartbeatFrequencyMS: 1000,
bufferCommands: false, // Disable mongoose buffering
bufferMaxEntries: 0 // and MongoDB driver buffering
}); That should help you get an error message. It might be that Mongoose isn't able to connect for some reason, and is stuck in a server selection loop. |
I am getting 3 types of error:
Btw, I am using MongoDB atlas as my DB server |
Try setting conn = mongoose.createConnection(uri, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 1000,
heartbeatFrequencyMS: 1000,
socketTimeoutMS: 5000, // <-- Add this
bufferCommands: false, // Disable mongoose buffering
bufferMaxEntries: 0 // and MongoDB driver buffering
}); The "connection timed out" error is often indicative of a very slow query timing out the socket. Another alternative: there is a slight race condition in your if (conn == null) {
conn = mongoose.createConnection(uri, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true,
bufferCommands: false, // Disable mongoose buffering
bufferMaxEntries: 0 // and MongoDB driver buffering
});
await conn;
for (const [key, value] of Object.entries(CollectionName)) {
conn.model(value, require(`../../schema/${value}`));
}
} else {
logger.writeActionLog("MongoDB", "Used cache");
await conn; // <-- add this
} |
Do you want to request a feature or report a bug?
bug report
What is the current behavior?
I am using Mongoose in AWS Lambda and using the following code to connect with MongoDB
When I execute any CRUD statement (e.g. aggregate), Mongoose can return result to in < 1s. However, it has a rare hanging case without any exception or error in the same CRUD. Even I wait it in 900s, it still hang.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
All CRUD statement should be always work.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose: ^5.10.9
Node.js 12.x
The text was updated successfully, but these errors were encountered: