Skip to content
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

Throw fastify-mongodb error instead of avvio error #134

Closed
2 tasks done
eisenhaus335 opened this issue Aug 6, 2021 · 9 comments · Fixed by #146
Closed
2 tasks done

Throw fastify-mongodb error instead of avvio error #134

eisenhaus335 opened this issue Aug 6, 2021 · 9 comments · Fixed by #146
Labels
good first issue Good for newcomers semver-minor Issue or PR that should land as semver minor

Comments

@eisenhaus335
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure it has not already been reported

Fastify version

3.20.0

Plugin version

4.0.0

Node.js version

15.13.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

20.04

Description

I am trying to connecting to mongodb with url like usual. I wonder why its timeout and especially by this module "avvio". Turns out i forget to whitelist my ip address and thats why i was rejected. But, i think would be good for fastify-mongodb to catch this timeout error when connecting db

rror: ERR_AVVIO_PLUGIN_TIMEOUT: plugin did not start in time: /home/wwww/product/node_modules/fastify-mongodb/index.js. You may have forgotten to call 'done' function or to resolve a Promise at Timeout._onTimeout (/home/wwwww/product/node_modules/avvio/plugin.js:123:19) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7) { code: 'ERR_AVVIO_PLUGIN_TIMEOUT', fn: <ref *1> [Function: fastifyMongodb] { default: [Circular *1], fastifyMongodb: [Circular *1], [Symbol(skip-override)]: true, [Symbol(fastify.display-name)]: 'fastify-mongodb', [Symbol(plugin-meta)]: { fastify: '>=1.0.0', name: 'fastify-mongodb' } } }

Steps to Reproduce

  1. connect db
  2. timeout
  3. console.log(err) show avvio error

Expected Behavior

Its should be mongodb error but avvio catch it instead

@eisenhaus335 eisenhaus335 changed the title Throw fastify-mongodb error on db connection Throw fastify-mongodb error instead of avvio error Aug 6, 2021
@mcollina
Copy link
Member

mcollina commented Aug 6, 2021

I think we need to pass a custom connectTimeoutMS option set to 5s when we create the MongoClient.

Wdyt?

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@eisenhaus335
Copy link
Author

I think this is problem of fastify.register that has timeout time when register plugin, if i read the error correctly. It would be best to catch the error than make connectTimeoutMS. I think adding custom connectTimeoutMS option will not catch the error. But not sure, maybe anyone has more idea on this? I also doesnt know how fastify works in general

@climba03003
Copy link
Member

climba03003 commented Aug 6, 2021

I think this is problem of fastify.register that has timeout time when register plugin, if i read the error correctly. It would be best to catch the error than make connectTimeoutMS. I think adding custom connectTimeoutMS option will not catch the error. But not sure, maybe anyone has more idea on this? I also doesnt know how fastify works in general

Inside the plugin, it already forward the error to fastify.
https://github.com/fastify/fastify-mongodb/blob/master/index.js#L90

As the mongodb default timeout (30s) is longer than fastify plugin timeout (10s), so it cannot forward the error properly.

@eisenhaus335
Copy link
Author

Anyone that would like to make PR request could make it. I tried to make test case and the code and struggling with that. I dont know how to make error case like make making the mongo to timeout

I am still very new in open project like this. The code still a bit advanced for me

@mcollina mcollina added semver-minor Issue or PR that should land as semver minor good first issue Good for newcomers labels Aug 6, 2021
@ihadabs
Copy link

ihadabs commented Aug 21, 2021

I'm using fastify-autoload to load my plugins and one of the files contains:

export default fp<FastifyMongodbOptions>(async function(fastify, opts) {
	await fastify.register(require('fastify-mongodb'), {
		// force to close the mongodb connection when app stopped
		// the default value is false
		forceClose: true,
		url: config.mongoUri,
		database: config.mongoDefaultDbName,
	});
});

for some reason its failing to load with the following error:

[App] Error: ERR_AVVIO_PLUGIN_TIMEOUT: plugin did not start in time: async function (fastify, opts) { -- await fastify.register(require('fastify-mongodb'), {. You may have forgotten to call 'done' function or to resolve a Promise
[App]     at Timeout._onTimeout (/Users/***/node_modules/avvio/plugin.js:123:19)
[App]     at listOnTimeout (internal/timers.js:554:17)
[App]     at processTimers (internal/timers.js:497:7) {
[App]   code: 'ERR_AVVIO_PLUGIN_TIMEOUT',
[App]   fn: <ref *1> [AsyncFunction (anonymous)] {
[App]     default: [Circular *1],
[App]     [Symbol(skip-override)]: true,
[App]     [Symbol(fastify.display-name)]: 'connector-auto-7',
[App]     [Symbol(plugin-meta)]: { name: 'connector-auto-7' }
[App]   }
[App] }

Giving that it worked before.

@climba03003
Copy link
Member

climba03003 commented Aug 22, 2021

I'm using fastify-autoload to load my plugins and one of the files contains:

export default fp<FastifyMongodbOptions>(async function(fastify, opts) {
	await fastify.register(require('fastify-mongodb'), {
		// force to close the mongodb connection when app stopped
		// the default value is false
		forceClose: true,
		url: config.mongoUri,
		database: config.mongoDefaultDbName,
	});
});

for some reason its failing to load with the following error:

[App] Error: ERR_AVVIO_PLUGIN_TIMEOUT: plugin did not start in time: async function (fastify, opts) { -- await fastify.register(require('fastify-mongodb'), {. You may have forgotten to call 'done' function or to resolve a Promise
[App]     at Timeout._onTimeout (/Users/***/node_modules/avvio/plugin.js:123:19)
[App]     at listOnTimeout (internal/timers.js:554:17)
[App]     at processTimers (internal/timers.js:497:7) {
[App]   code: 'ERR_AVVIO_PLUGIN_TIMEOUT',
[App]   fn: <ref *1> [AsyncFunction (anonymous)] {
[App]     default: [Circular *1],
[App]     [Symbol(skip-override)]: true,
[App]     [Symbol(fastify.display-name)]: 'connector-auto-7',
[App]     [Symbol(plugin-meta)]: { name: 'connector-auto-7' }
[App]   }
[App] }

Giving that it worked before.

@ihadabs If it throw about fastify-mongodb, most of the reason is it cannot connect to the database instance. Please check the database connectivity.

For this issue, I have tested both connectTimeoutMS and socketTimeoutMS, they do not behave what I believe. So, I think it is hard to solve this issue in a short period of time.
cc @eisenhaus335

@floydjones1
Copy link

floydjones1 commented Sep 24, 2021

I'm using fastify-autoload to load my plugins and one of the files contains:

export default fp<FastifyMongodbOptions>(async function(fastify, opts) {
	await fastify.register(require('fastify-mongodb'), {
		// force to close the mongodb connection when app stopped
		// the default value is false
		forceClose: true,
		url: config.mongoUri,
		database: config.mongoDefaultDbName,
	});
});

for some reason its failing to load with the following error:

[App] Error: ERR_AVVIO_PLUGIN_TIMEOUT: plugin did not start in time: async function (fastify, opts) { -- await fastify.register(require('fastify-mongodb'), {. You may have forgotten to call 'done' function or to resolve a Promise
[App]     at Timeout._onTimeout (/Users/***/node_modules/avvio/plugin.js:123:19)
[App]     at listOnTimeout (internal/timers.js:554:17)
[App]     at processTimers (internal/timers.js:497:7) {
[App]   code: 'ERR_AVVIO_PLUGIN_TIMEOUT',
[App]   fn: <ref *1> [AsyncFunction (anonymous)] {
[App]     default: [Circular *1],
[App]     [Symbol(skip-override)]: true,
[App]     [Symbol(fastify.display-name)]: 'connector-auto-7',
[App]     [Symbol(plugin-meta)]: { name: 'connector-auto-7' }
[App]   }
[App] }

Giving that it worked before.

Had the same issue just had to debug more and my mongo docker container wasn't bound properly lol

@hoanghiep1x0
Copy link

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 how to fix it

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-truyen/service-authencation/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' }
  }
}

@Uzlopak
Copy link
Contributor

Uzlopak commented Sep 20, 2023

This indicates that the connection to the db could not be established, as the plugin never resolves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers semver-minor Issue or PR that should land as semver minor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants