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

Skip to content

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

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
Mar 3, 2023

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Feb 24, 2023

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 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 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 handleSignal() 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

@lyrixx lyrixx force-pushed the console-fix-signal-handling branch from af0f5fe to fd64a13 Compare February 24, 2023 21:21
@lcobucci
Copy link
Contributor

This was the BC-break I referred to when I brought up the initial issue 😅

@lyrixx thanks for your work here, there are indeed many factors to take into account when tweaking signal handling.

For my use case, the solution will work fine. It feels a bit cumbersome to modify the event state buuuut it's fine.

It's really important to document the nuances and what's expected from each different use case 👍

@lyrixx
Copy link
Member Author

lyrixx commented Feb 25, 2023

Yes, it's not so cool to have to edit the event, but we must do it since we cannot now if the end user will stop / exit / return itself.

So by default we should mimic PHP, and the user can opt-in for managing exit themself.

@lyrixx lyrixx force-pushed the console-fix-signal-handling branch 2 times, most recently from a24c7e8 to 3091710 Compare February 25, 2023 15:13
@fabpot
Copy link
Member

fabpot commented Feb 25, 2023

@lyrixx You can rebase this one (I've merged up the other 2 PRs).

@lyrixx lyrixx force-pushed the console-fix-signal-handling branch 2 times, most recently from 47aee88 to 35ccc92 Compare February 25, 2023 22:55
@lyrixx
Copy link
Member Author

lyrixx commented Feb 25, 2023

Rebase ✅

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.

👍 for this. The CHANGELOG should mention the BC break though

@lyrixx
Copy link
Member Author

lyrixx commented Feb 26, 2023

What bc break are you talking about? The new method in the interface? I should update the upgrade.md too!

@chalasr
Copy link
Member

chalasr commented Feb 26, 2023

Yes!

@lyrixx lyrixx force-pushed the console-fix-signal-handling branch from 35ccc92 to f4fe1c1 Compare February 26, 2023 17:00
@lyrixx
Copy link
Member Author

lyrixx commented Feb 26, 2023

Fixed

@lyrixx

This comment was marked as resolved.

@lyrixx lyrixx force-pushed the console-fix-signal-handling branch from f4fe1c1 to 09dbb75 Compare March 3, 2023 13:41
@lyrixx
Copy link
Member Author

lyrixx commented Mar 3, 2023

Thanks for the review!

I pushed a new version without the new method on the interface!

The new API is even simpler!

@lyrixx lyrixx force-pushed the console-fix-signal-handling branch 3 times, most recently from 4c56899 to 392f0ff Compare March 3, 2023 14:19
@lyrixx lyrixx force-pushed the console-fix-signal-handling branch 3 times, most recently from 039c1a6 to e0b43d2 Compare March 3, 2023 14:45
@nicolas-grekas nicolas-grekas changed the title [Console] Fix issue with signal handling [Console] Add getExitCode() method to SignalableCommandInterface Mar 3, 2023
@lyrixx lyrixx force-pushed the console-fix-signal-handling branch from e0b43d2 to 3bbe3d1 Compare March 3, 2023 15:15
@lyrixx lyrixx force-pushed the console-fix-signal-handling branch from 3bbe3d1 to 14a4f48 Compare March 3, 2023 15:33
@lyrixx lyrixx force-pushed the console-fix-signal-handling branch from 14a4f48 to dab0517 Compare March 3, 2023 15:42
@lyrixx lyrixx force-pushed the console-fix-signal-handling branch from dab0517 to 1650e38 Compare March 3, 2023 15:47
@lyrixx lyrixx changed the title [Console] Add getExitCode() method to SignalableCommandInterface [Console] Add support for managing exit code while handling signals Mar 3, 2023
@nicolas-grekas
Copy link
Member

Thank you @lyrixx.

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] Unexpected behavior on CONTROL-C
9 participants