Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminate Caliper workers on interrupting Caliper manager #1435

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/caliper-cli/lib/launch/lib/launchManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ class LaunchManager {
sutType, Constants.Factories.Connector, require);

const engine = new CaliperEngine(benchmarkConfig, networkConfig, connectorFactory);
process.on('SIGINT', async () => {
// support a force stop
if (!this.terminationAlreadyRequested) {
this.terminationAlreadyRequested = true;
logger.info('Request to terminate received, stopping workers');
try {
await engine.stop();
} catch(error) {
logger.error(`Failed to stop workers: ${error}`);
process.exit(1);
}
logger.info('Workers terminated');
process.exit(0);
} else {
logger.info('Termination already requested, terminating immediately');
process.exit(2);
}
});

const response = await engine.run();

if (response === 0) {
Expand Down
9 changes: 9 additions & 0 deletions packages/caliper-core/lib/manager/caliper-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@

return this.returnCode;
}

/**
* Stops the benchmark run
*/
async stop() {
if (this.roundOrchestrator) {
await this.roundOrchestrator.stop();

Check warning on line 189 in packages/caliper-core/lib/manager/caliper-engine.js

View check run for this annotation

Codecov / codecov/patch

packages/caliper-core/lib/manager/caliper-engine.js#L189

Added line #L189 was not covered by tests
}
}
}

module.exports = CaliperEngine;
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,24 @@
}
}

// clean up, with "silent" failure handling
try {
this.report.printResultsByRound();
await this.report.finalize();
} catch (err) {
logger.error(`Error while finalizing the report: ${err.stack || err}`);
}

await this.stop();

Check warning on line 235 in packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js

View check run for this annotation

Codecov / codecov/patch

packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js#L235

Added line #L235 was not covered by tests

let benchEndTime = Date.now();
logger.info(`Benchmark finished in ${(benchEndTime - benchStartTime)/1000.0} seconds. Total rounds: ${success + failed}. Successful rounds: ${success}. Failed rounds: ${failed}.`);

Check warning on line 238 in packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js

View check run for this annotation

Codecov / codecov/patch

packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js#L237-L238

Added lines #L237 - L238 were not covered by tests
}

/**
* Stops the benchmark.
*/
async stop() {
// clean up, with "silent" failure handling
try {
await this.monitorOrchestrator.stopAllMonitors();
} catch (err) {
Expand All @@ -244,9 +254,6 @@
} 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}.`);
}
}

Expand Down
Loading