Skip to content

CLI: SIGINT handler crashes and exitWithStatus double-exits #4

Description

@dalberola

Two correctness bugs in packages/dredd/lib/CLI.js, both [verified] against source.

1. SIGINT handler crashes (commandSigInt)

packages/dredd/lib/CLI.js:504-507

commandSigInt() {
  logger.error('\nShutting down from keyboard interruption (Ctrl+C)');
  this.dreddInstance.transactionsComplete(() => this._processExit(0));
}
  • transactionsComplete is defined nowhere in lib/ (grep -rn transactionsComplete packages/dredd/lib returns only this call site). The Dredd class has no such method.
  • The handler is also registered unbound: process.on('SIGINT', this.commandSigInt) (CLI.js:514), so this is not the CLI instance at call time and this.dreddInstance is wrong regardless.

Failure: pressing Ctrl+C during a run throws TypeError instead of shutting down gracefully.

2. exitWithStatus never returns after the error path

packages/dredd/lib/CLI.js:525-538

exitWithStatus(error, stats) {
  if (error) {
    if (error.message) { logger.error(error.message); }
    this._processExit(1);              // no return
  }
  if (stats.failures + stats.errors > 0) {  // still runs
    this._processExit(1);
  } else {
    this._processExit(0);
  }
}

For the programmatic API (this.exit configured), _processExit does not call process.exit (see Dredd.js:212+), so the custom exit callback fires twice, and stats.failures throws when stats is undefined on the error path.

Tasks

  • Bind commandSigInt (e.g. process.on('SIGINT', this.commandSigInt.bind(this))) and replace the call to the nonexistent transactionsComplete with a real graceful-shutdown path.
  • Add an early return after the error-path _processExit(1) in exitWithStatus.
  • Add/restore a unit test for SIGINT shutdown and for the error exit-code path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions