Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] #47809 remove exit() call in last SignalHandler #48299

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

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

akuzia
Copy link
Contributor

@akuzia akuzia commented Nov 23, 2022

Q A
Branch? 6.3
Bug fix? yes
BC? yes
New feature? no
Deprecations? not sure
Tickets Fix #47809
License MIT

This PR possibly introduces some breaking changes.

Remove last SignalHandler exit() call in Application:doRunCommand introduced in df57119.

For more context see #47809

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me as a bugfix.

@akuzia
Copy link
Contributor Author

akuzia commented Nov 23, 2022

Works for me as a bugfix.

It is possibly a breaking change, as some of the users may or may not introduce own handlers to bypass this. Not sure if chanelog or doc changes needed

Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except two little comments, I'm 👍🏼

@akuzia akuzia force-pushed the issue-47809 branch 2 times, most recently from bbf315e to 7f44f7b Compare November 24, 2022 09:06
@fabpot
Copy link
Member

fabpot commented Nov 26, 2022

That's a behavior change, so it cannot be merged in 5.4. It needs to target 6.3.
A changelog is also needed to explain the changes.

@fabpot fabpot modified the milestones: 5.4, 6.3 Nov 26, 2022
@akuzia akuzia changed the base branch from 5.4 to 6.3 December 1, 2022 15:03
@akuzia
Copy link
Contributor Author

akuzia commented Dec 1, 2022

@fabpot I've rebased to 6.3 and added changelog entry. Phrasing may be a bit to complex, I've opened to suggestions

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with minor suggestion

@fabpot
Copy link
Member

fabpot commented Dec 9, 2022

Thank you @akuzia.

@fabpot fabpot merged commit ed1e8be into symfony:6.3 Dec 9, 2022
@akuzia akuzia deleted the issue-47809 branch December 9, 2022 08:00
fabpot added a commit that referenced this pull request Dec 17, 2022
This PR was merged into the 6.3 branch.

Discussion
----------

[Console] Fix a test when pcntl is not available

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | ~
| License       | MIT
| Doc PR        | ~

Same as #48694, about #48299.

Commits
-------

2ad8bb1 [Console] Fix a test when pcntl is not available
@lyrixx
Copy link
Member

lyrixx commented Feb 23, 2023

  1. Hmm, this PR broke something 😬

With the following code (only):

#[AsCommand(
    name: 'loop',
)]
class LoopCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        while (true) {
            echo "hello\n";
            usleep(100_000);
        }

        return Command::SUCCESS;
    }
}

when I hit CTRL+C, it does not stop anymore. this is legit since we remove the exit() call!


I'll work on it ASAP

nicolas-grekas added a commit that referenced this pull request Mar 3, 2023
…dling signals (lyrixx)

This PR was merged into the 6.3 branch.

Discussion
----------

[Console] Add support for managing exit code while handling signals

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | yes
| Deprecations? | yes (new method in interrface)
| Tickets       | Fix #48340
| License       | MIT
| Doc PR        |

Signal handling is hard! This commit fixes an issue introduced in bb7779d, see this [comment](#48299 (comment)) for more information.

Symfony registers by default 4 signals, the most common ones: `SIGINT`,
`SIGTERM`, `SIGUSR1`, and `SIGUSR2`.

When no signal handler are registered, the default behavior is to stop the
execution of the current script, to replication PHP default behavior.

That's why we had a call to exit(0), before
bb7779d and that's why it must be restored.

However, the concerns raised in the
[issue](#47809) are valid, and we
should provided a solution for this.

Now we have the following features:

* By default, we exit, like PHP does by default on `SIGINT`, `SIGTERM`;
* It's possible to tell via the event to not exit, by calling
  `$event->abortExit()`;
* It's possible to tell via the event to exit with a custom code, by calling
  `$event->setExitCode($code)`;
* It's possible, via the `SignalableCommandInterface` to tell via the command to
  not exit, by returning `int|false` from `handleSigbal()` method
* Fixed case when there is not event to dispatch at all, but the command register some

I think we have all we need now. I added more tests to ensure we don't break
anything in the future.

---

Sorry for the massive ping here, but this is bit like an a house of cards to
make it work in any case. I hope I didn't miss anything.

ping `@akuzia` `@lcobucci` `@GromNaN` `@olegpro`

Commits
-------

1650e38 [Console] Add support for managing exit code while handling signals
@fabpot fabpot mentioned this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Console] Commands aren't able to fully gracefully exit by themselves
6 participants