Plugin did not start in time: 'database-auto-3' when register with `await`
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
4.0.0
### Plugin version
4.1.0
### Node.js version
18.16.0
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
11.3
### Description
## Files
### plugins/database.js
```js
import fp from 'fastify-plugin'
import fastifyMysql from '@fastify/mysql'
export default fp(async (fastify, opts) => {
const dbConfig = opts.db;
await fastify.register(fastifyMysql, {
promise: true,
host: dbConfig.host,
port: dbConfig.port,
user: dbConfig.user,
password: dbConfig.password,
database: dbConfig.database
})
fastify.addHook('onRequest', async (request) => {
request.db = await fastify.mysql.getConnection();
});
fastify.addHook('onResponse', async (request) => {
if (request.db) {
request.db.release();
}
});
})
```
### app.js
```js
export default async function (fastify, opts) {
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'plugins'),
options: Object.assign(options[opts.env], opts)
})
}
```
## If don't use **await** fastify.register, sometimes this error occurs when starting
```
[0] AvvioError [Error]: Plugin did not start in time: '@fastify/mysql'. You may have forgotten to call 'done' function or to resolve a Promise
......
```
## If use await, sometimes this error occurs when starting
```
[0] AvvioError [Error]: Plugin did not start in time: 'database-auto-3'. You may have forgotten to call 'done' function or to resolve a Promise
[0] at Timeout._onTimeout (/root/**/**/node_modules/avvio/plugin.js:122:19)
[0] at listOnTimeout (node:internal/timers:569:17)
[0] at process.processTimers (node:internal/timers:512:7) {
[0] code: 'AVV_ERR_READY_TIMEOUT',
[0] fn: <ref *1> [AsyncFunction (anonymous)] {
[0] default: [Circular *1],
[0] [Symbol(skip-override)]: true,
[0] [Symbol(fastify.display-name)]: 'database-auto-3',
[0] [Symbol(plugin-meta)]: { name: 'database-auto-3' }
[0] }
[0] }
```
### Steps to Reproduce
There seems to be no stable reproducible steps
### Expected Behavior
Stable operation without error
关闭于 2023-11-08 1 条评论