From 6a41daff622828dce0e471efac27e823497fcbd8 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 5 Jan 2023 19:36:06 -0500 Subject: [PATCH] *Ensure the swarm properly shuts down and un-announces itself --- src/index.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0569913..4443c13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { start as startRelay } from "./modules/relay.js"; import { start as startApp } from "./modules/app"; import config from "./config.js"; import { loadPlugins } from "./modules/plugin.js"; -import { start as startSwarm } from "./modules/swarm.js"; +import { start as startSwarm, get as getSwarm } from "./modules/swarm.js"; import * as bip39 from "@scure/bip39"; import { wordlist } from "@scure/bip39/wordlists/english"; @@ -26,9 +26,11 @@ boot(); process.on("uncaughtException", function (err) { console.log(`Caught exception: ${err.message} ${err.stack}`); }); -process.on("SIGINT", function () { + +async function shutdown() { + await getSwarm().destroy(); process.exit(); -}); -process.on("SIGTERM", function () { - process.exit(); -}); +} + +process.on("SIGINT", shutdown); +process.on("SIGTERM", shutdown);