From 45aef719d32f23d65748662be3725035de723618 Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 8 Feb 2023 11:41:23 -0900 Subject: [PATCH] Make sure heartbeat isActive resolves This does not seem to actually cause an issue (not resolving ends up with the same behavior as resolving with false) but I am not sure if the hanging promises would be a memory leak so seems best to fix. --- src/node/routes/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/node/routes/index.ts b/src/node/routes/index.ts index 96928493b..a235c4252 100644 --- a/src/node/routes/index.ts +++ b/src/node/routes/index.ts @@ -33,7 +33,15 @@ import { CodeServerRouteWrapper } from "./vscode" export const register = async (app: App, args: DefaultedArgs): Promise => { const heart = new Heart(path.join(paths.data, "heartbeat"), async () => { return new Promise((resolve, reject) => { + // getConnections appears to not call the callback when there are no more + // connections. Feels like it must be a bug? For now add a timer to make + // sure we eventually resolve. + const timer = setTimeout(() => { + logger.debug("Node failed to respond with connections; assuming zero") + resolve(false) + }, 5000) app.server.getConnections((error, count) => { + clearTimeout(timer) if (error) { return reject(error) }