drush icon indicating copy to clipboard operation
drush copied to clipboard

Regression: Drush 13.3 does not properly handle SIGQUIT signal

Open Chi-teck opened this issue 1 year ago • 4 comments

That apparently is caused by #6124.

Here is example of a simple long running Drush command


#[AsCommand( 'example')]
final class ExampleCommand extends Command implements SignalableCommandInterface {

  /**
   * Signal flag.
   */
  private bool $stop = FALSE;


  /**
   * {@inheritdoc}
   */
  protected function execute(InputInterface $input, OutputInterface $output): int {
    for ($i = 1; $i <= 60; $i++, sleep(1)) {
      echo '.';
      if ($this->stop) {
        echo 'Signal received...', \PHP_EOL;
        sleep(5);
        echo 'Done!', \PHP_EOL;
        break;
      }
    }
    return 0;
  }

  /**
   * {@inheritdoc}
   */
  public function getSubscribedSignals(): array {
    return [\SIGTERM, \SIGQUIT, \SIGINT];
  }

  /**
   * {@inheritdoc}
   */
  public function handleSignal(int $signal): false|int {
    $this->stop = TRUE;
    return FALSE;
  }

}

Start the above command and send SIGQUIT (Ctrl + \) to it.

Output Drush 13.2 (correct)

$ ./vendor/bin/drush example
....^\.Signal received!
Done!

Output Drush 13.3 (wrong)

$ ./vendor/bin/drush example
....^\.Signal received!
Quit (core dumped)
$ Done!

Note that in the last example "Done!" appears when Drush was already terminated. If a command is managed through some process manager, i.e. Supervisor, such behavior causes orphan processes.

Chi-teck avatar Oct 16 '24 17:10 Chi-teck

The new way to launch Drush creates two additional shell processes besides the PHP. Also some people reported that Drush 13.3 is not working on Windows because of this change.

Chi-teck avatar Oct 16 '24 18:10 Chi-teck

@Chi-teck Could you try to run ./vendor/drush/drush/drush.php directly? Just to make sure, this executable has the correct behaviour?

webflo avatar Oct 17 '24 16:10 webflo

Yes, drush.php works correctly.

$ ./vendor/bin/drush example
.....^\.Signal received...
Quit (core dumped)
$ Done!

$ ./vendor/drush/drush/drush.php example
.....^\.Signal received...
Done!

Chi-teck avatar Oct 17 '24 16:10 Chi-teck

In the original PR I implemented it without exec, because the Composer Wrapper script also works this way.

https://github.com/composer/composer/blob/main/src/Composer/Installer/BinaryInstaller.php#L409

webflo avatar Oct 17 '24 17:10 webflo

I'm proposing reverting the bash entrypoint in #6146.

greg-1-anderson avatar Oct 25 '24 22:10 greg-1-anderson

Use latest composer and Drush 13.3.1+

weitzman avatar Oct 29 '24 19:10 weitzman