Skip to content

Commit

Permalink
Added pluginTimeout option. (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Aug 24, 2018
1 parent 22bf64c commit 50bcf6b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/Factory.md
Expand Up @@ -185,3 +185,12 @@ fastify.get('/', (request, reply) => {
console.log(request.raw.hostname)
})
```

<a name="plugin-timeout"></a>
### `pluginTimeout`

The maximum amount of time in milliseconds in which a plugin can load.
If not, [`ready`](https://github.com/fastify/fastify/blob/master/docs/Server-Methods.md#ready)
will complete with an `Error` with code `'ERR_AVVIO_PLUGIN_TIMEOUT'`.

+ Default: `0` (disabled)
3 changes: 2 additions & 1 deletion fastify.js
Expand Up @@ -85,7 +85,8 @@ function build (options) {
const onResponseCallback = hasLogger ? loggerUtils.onResponseCallback : noop

const app = avvio(fastify, {
autostart: false
autostart: false,
timeout: Number(options.pluginTimeout) || 0
})
// Override to allow the plugin incapsulation
app.override = override
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -105,7 +105,7 @@
"@types/pino": "^4.16.0",
"abstract-logging": "^1.0.0",
"ajv": "^6.5.2",
"avvio": "^5.6.0",
"avvio": "^5.8.0",
"end-of-stream": "^1.4.1",
"fast-json-stringify": "^1.5.4",
"find-my-way": "^1.15.0",
Expand Down
14 changes: 14 additions & 0 deletions test/plugin.test.js
Expand Up @@ -489,3 +489,17 @@ test('plugin metadata - dependencies (nested)', t => {
next()
}
})

test('pluginTimeout', t => {
t.plan(2)
const fastify = Fastify({
pluginTimeout: 10
})
fastify.register(function (app, opts, next) {
// to no call next on purpose
})
fastify.ready((err) => {
t.ok(err)
t.equal(err.code, 'ERR_AVVIO_PLUGIN_TIMEOUT')
})
})

0 comments on commit 50bcf6b

Please sign in to comment.