fastify-mongodb: Error Plugin did not start in time: '@fastify/mongodb'. You may have forgotten to call 'done' function or to resolve a Promise
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.x
Plugin version
^6.0.1
Node.js version
16.0.9
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
ventura 13.5.2
Description
Why does connect localhost:27017 work. but connect to mongo with the address mongodb+srv://user:pass@cluster0.m9frj.mongodb.net/ then get an error
Plugin file
'use strict'
const fp = require('fastify-plugin')
const fastifyMongo = require('@fastify/mongodb')
module.exports = fp(async function datasourcePlugin(fastify, opts, next) {
try {
fastify.register(fastifyMongo, {
forceClose: true,
connectTimeoutMS: 10000,
url: fastify.secrets.MONGO_URL
});
} catch (err) {
next(err);
}
}, {
dependencies: ['application-config']
})
Plugin did not start in time: ‘@fastify/mongodb’. You may have forgotten to call ‘done’ function or to resolve a Promise
Steps to Reproduce
- config plugin and run with localhost => work
- config with mongolab => error
Expected Behavior
Plugin did not start in time: '@fastify/mongodb'. You may have forgotten to call 'done' function or to resolve a Promise
at Timeout._onTimeout (/Users/admin/Desktop/app/docker/service-data/node_modules/avvio/plugin.js:122:19)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
code: 'AVV_ERR_READY_TIMEOUT',
fn: <ref *1> [AsyncFunction: fastifyMongodb] {
default: [Circular *1],
fastifyMongodb: [Circular *1],
ObjectId: [Function: ObjectId] {
getInc: [Function (anonymous)],
generate: [Function (anonymous)],
createPk: [Function (anonymous)],
createFromTime: [Function (anonymous)],
createFromHexString: [Function (anonymous)],
isValid: [Function (anonymous)],
fromExtendedJSON: [Function (anonymous)],
index: 16644978
},
[Symbol(skip-override)]: true,
[Symbol(fastify.display-name)]: '@fastify/mongodb',
[Symbol(plugin-meta)]: { fastify: '4.x', name: '@fastify/mongodb' }
}
}
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 19 (7 by maintainers)
Thank you very much. after fixing with options with pluginTimeout server it is working.
The MongoDB Altas connection consist too many steps.
Normally, a connection will be resolved within 1 second. More than 10 second will exist in a slow network.
So, you would need to measure how much time you need to connect to the MongoDB Altas.
Increase the pluginTimeout to 30s or longer, if a single connection required more than 30s than it is absolutely something wrong in your network stack.
You are not doing the same as this plugin, and you ignore the connection state by resolving the plugin immediately. The below one is waiting for the connection properly.
was about to say that in your first code version you are mixin async and next, the latter version of the code should be fine.
I think it may be a firewall or something. I would suggest to debug it with:
This indicates that the connection to the db could not be established, as the plugin never resolves.