diff --git a/packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js b/packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js index 6a2b6b58a..df813f30f 100644 --- a/packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js +++ b/packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js @@ -177,6 +177,12 @@ class RoundOrchestrator { logger.error(`Could not prepare worker connections: ${err.stack || err}`); } + process.on('SIGINT', async () => { + logger.info('SIGINT received, stopping workers'); + await this._cleanup(); + process.exit(0); + }); + let benchStartTime = Date.now(); for (const [index, roundConfig] of roundConfigs.entries()) { @@ -225,7 +231,6 @@ class RoundOrchestrator { } } - // clean up, with "silent" failure handling try { this.report.printResultsByRound(); await this.report.finalize(); @@ -233,6 +238,17 @@ class RoundOrchestrator { logger.error(`Error while finalizing the report: ${err.stack || err}`); } + await this._cleanup(); + + let benchEndTime = Date.now(); + logger.info(`Benchmark finished in ${(benchEndTime - benchStartTime)/1000.0} seconds. Total rounds: ${success + failed}. Successful rounds: ${success}. Failed rounds: ${failed}.`); + } + + /** + * Stops the benchmark. + */ + async _cleanup() { + // clean up, with "silent" failure handling try { await this.monitorOrchestrator.stopAllMonitors(); } catch (err) { @@ -244,9 +260,6 @@ class RoundOrchestrator { } catch (err) { logger.error(`Error while stopping workers: ${err.stack || err}`); } - - let benchEndTime = Date.now(); - logger.info(`Benchmark finished in ${(benchEndTime - benchStartTime)/1000.0} seconds. Total rounds: ${success + failed}. Successful rounds: ${success}. Failed rounds: ${failed}.`); } }