From dd0f517ddc74207caadacfcefb2b086b0e56275e Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Mon, 23 Sep 2024 13:59:34 -0400 Subject: [PATCH] add backend patch for force closing http connections when stopping fastify server --- ...1+001+fastify-controller-force-close.patch | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/backend/patches/@comapeo+core+1.0.1+001+fastify-controller-force-close.patch diff --git a/src/backend/patches/@comapeo+core+1.0.1+001+fastify-controller-force-close.patch b/src/backend/patches/@comapeo+core+1.0.1+001+fastify-controller-force-close.patch new file mode 100644 index 000000000..9ed3c51f2 --- /dev/null +++ b/src/backend/patches/@comapeo+core+1.0.1+001+fastify-controller-force-close.patch @@ -0,0 +1,20 @@ +diff --git a/node_modules/@comapeo/core/src/fastify-controller.js b/node_modules/@comapeo/core/src/fastify-controller.js +index a84c600..d7c748c 100644 +--- a/node_modules/@comapeo/core/src/fastify-controller.js ++++ b/node_modules/@comapeo/core/src/fastify-controller.js +@@ -64,7 +64,14 @@ export class FastifyController { + + async #stopServer() { + const { server } = this.#fastify +- await promisify(server.close.bind(server))() ++ ++ const closePromise = promisify(server.close.bind(server))() ++ ++ // Need to force close some connections (see https://github.com/digidem/comapeo-mobile/issues/611#issuecomment-2368795563) ++ // 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 + } + + /**