From b18a8a3f13e147b607887b4adeadf49c8d7532fa Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Fri, 5 Jan 2018 11:54:48 +0530 Subject: [PATCH] bin: handle close when interrupted --- bin/node | 4 ++++ bin/spvnode | 4 ++++ bin/wallet | 4 ++++ lib/node/fullnode.js | 3 ++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/node b/bin/node index 1eb955b5..105de2dc 100755 --- a/bin/node +++ b/bin/node @@ -44,6 +44,10 @@ process.on('unhandledRejection', (err, promise) => { throw err; }); +process.on('SIGINT', async () => { + await node.close(); +}); + (async () => { await node.ensure(); await node.open(); diff --git a/bin/spvnode b/bin/spvnode index 3abd0d78..8e541c6e 100755 --- a/bin/spvnode +++ b/bin/spvnode @@ -33,6 +33,10 @@ process.on('unhandledRejection', (err, promise) => { throw err; }); +process.on('SIGINT', async () => { + await node.close(); +}); + (async () => { await node.ensure(); await node.open(); diff --git a/bin/wallet b/bin/wallet index 4cf1d4e2..c0b40838 100755 --- a/bin/wallet +++ b/bin/wallet @@ -38,6 +38,10 @@ process.on('unhandledRejection', (err, promise) => { throw err; }); +process.on('SIGINT', async () => { + await node.close(); +}); + (async () => { await node.ensure(); await node.open(); diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index 47ab4b38..d7daa0a3 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -251,9 +251,10 @@ class FullNode extends Node { await this.miner.close(); await this.mempool.close(); await this.chain.close(); - await this.handleClose(); this.logger.info('Node is closed.'); + + await this.handleClose(); } /**