Closed aguegu closed 2 years ago
Hi, I tried your example with fastify v4 and it worked. I exited the process via SIGINT.
'use strict'
const fastify = require('fastify')({
logger: {
level: 'info',
},
})
fastify.register(require('./')).after((err) => {
fastify.log.error(err)
// Register custom clean up handler
fastify.gracefulShutdown((code, cb) => {
fastify.log.info("dddddddddddd")
cb()
})
})
const schema = {
schema: {
response: {
200: {
type: 'object',
properties: {
hello: {
type: 'string',
},
},
},
},
},
}
fastify.get('/', schema, function (req, reply) {
reply.send({ hello: 'world' })
})
fastify.listen(3000, (err) => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
^C{"level":30,"time":1655750151076,"pid":72447,"hostname":"pop-os","plugin":"fastify-graceful-shutdown","signal":"SIGINT","msg":"received signal"}
{"level":30,"time":1655750151076,"pid":72447,"hostname":"pop-os","plugin":"fastify-graceful-shutdown","signal":"SIGINT","msg":"triggering close hook"}
{"level":30,"time":1655750151076,"pid":72447,"hostname":"pop-os","msg":"dddddddddddd"}
{"level":30,"time":1655750151077,"pid":72447,"hostname":"pop-os","plugin":"fastify-graceful-shutdown","signal":"SIGINT","msg":"process terminated"}
I'm glad in works in fastify@4.
When I created this issue, it is around fastify@3.28.0.
With simple demo like below.
In logs I could find line like
But in the graceful shutdown handler, it could not log into app.log. I think it would make more sense to log some shutdown process within it.