From 140fc0c5e1459db1e0760b82cd46fe64b26f60f8 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 29 Sep 2020 23:13:22 +0700 Subject: [PATCH] Bugfix: Mempool and blocks disk cache not saved on exit when using cluster. --- backend/src/api/disk-cache.ts | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/backend/src/api/disk-cache.ts b/backend/src/api/disk-cache.ts index 1e35fdf68..50f66b6c5 100644 --- a/backend/src/api/disk-cache.ts +++ b/backend/src/api/disk-cache.ts @@ -7,17 +7,15 @@ class DiskCache { static FILE_NAME = './cache.json'; constructor() { - if (cluster.isMaster) { - process.on('SIGINT', () => { - this.saveCacheToDisk(); - process.exit(2); - }); + process.on('SIGINT', () => { + this.saveCacheToDisk(); + process.exit(2); + }); - process.on('SIGTERM', () => { - this.saveCacheToDisk(); - process.exit(2); - }); - } + process.on('SIGTERM', () => { + this.saveCacheToDisk(); + process.exit(2); + }); } saveCacheToDisk() { @@ -33,12 +31,8 @@ class DiskCache { if (cacheData) { console.log('Restoring mempool and blocks data from disk cache'); const data = JSON.parse(cacheData); - if (data.mempool) { - memPool.setMempool(data.mempool); - blocks.setBlocks(data.blocks); - } else { - memPool.setMempool(data); - } + memPool.setMempool(data.mempool); + blocks.setBlocks(data.blocks); } }