From 90c0016397fd3c4c0ac0183fd44a999c8cd90dcb Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Mon, 23 Sep 2024 14:36:43 -0400 Subject: [PATCH] fix: close idle connections when stopping FastifyController --- src/fastify-controller.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/fastify-controller.js b/src/fastify-controller.js index a84c600a5..66e3a2948 100644 --- a/src/fastify-controller.js +++ b/src/fastify-controller.js @@ -64,7 +64,13 @@ export class FastifyController { async #stopServer() { const { server } = this.#fastify - await promisify(server.close.bind(server))() + + const closePromise = promisify(server.close.bind(server))() + + // We call this after `server.close()` as recommended by the Node docs (see https://nodejs.org/docs/latest-v20.x/api/http.html#servercloseidleconnections) + server.closeIdleConnections() + + await closePromise } /**