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

Regression: Drush 13.3 does not properly handle SIGQUIT signal #6137

Open
Chi-teck opened this issue Oct 16, 2024 · 4 comments
Open

Regression: Drush 13.3 does not properly handle SIGQUIT signal #6137

Chi-teck opened this issue Oct 16, 2024 · 4 comments

Comments

@Chi-teck
Copy link
Collaborator

Chi-teck commented Oct 16, 2024

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 Chi-teck changed the title Regression: Drush 13.3 does not properly handle SIGQUIT signa. Regression: Drush 13.3 does not properly handle SIGQUIT signal Oct 16, 2024
@Chi-teck
Copy link
Collaborator Author

Chi-teck commented Oct 16, 2024

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.

@webflo
Copy link
Contributor

webflo commented Oct 17, 2024

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

@Chi-teck
Copy link
Collaborator Author

Yes, drush.php works correctly.

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

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

@webflo
Copy link
Contributor

webflo commented Oct 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants