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

Skip to content

Fixes #43866 configurable stop signals for messenger #44305

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

Closed
wants to merge 1 commit into from

Conversation

Warxcell
Copy link
Contributor

@Warxcell Warxcell commented Nov 27, 2021

Q A
Branch? 6.1
Bug fix? yes
New feature? yes
Deprecations? yes
Tickets Fix #43866
License MIT
Doc PR symfony/symfony-docs# TODO

@carsonbot
Copy link

Hey!

I think @ruudk has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

Copy link
Contributor

@ruudk ruudk left a comment

Choose a reason for hiding this comment

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

Looks great, added a few comments.

@@ -1,5 +1,6 @@
framework:
messenger:
stop_signals: SIGTERM
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this have to be plural (a list of signals) instead of just 1 signal?

Suggested change
stop_signals: SIGTERM
stop_signal: SIGTERM

Copy link
Contributor Author

@Warxcell Warxcell Nov 28, 2021

Choose a reason for hiding this comment

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

in case project is used in several envs (docker FPM alpine environment, and classical VMs/bare-metal with supervisor) where signals could be different.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then configure the correct signal for that env. Doesn't make sense (to me) to just fire all the signals.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed with @Warxcell. we should allow multiple signals.

Comment on lines 35 to 45
private function strsignal(int $signal): string
{
foreach (get_defined_constants(true)['pcntl'] as $name => $num) {
// the _ is to ignore SIG_IGN and SIG_DFL and SIG_ERR and SIG_BLOCK and SIG_UNBLOCK and SIG_SETMARK, and maybe more, who knows
if ($num === $signal && 'SIG' === substr($name, 0, 3) && '_' !== $name[3]) {
return $name;
}
}

throw new \InvalidArgumentException(sprintf('The signal "%d" is not valid.', $signal));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this responsibility to the compilation/configuration step and just always have the signal int injected via the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the case, but for logger, we need the name of the signal - so I need to reverse the logic - get the signal name by its id (int)

@jderusse jderusse modified the milestones: 6.0, 6.1 Nov 28, 2021
Copy link
Member

@jderusse jderusse left a comment

Choose a reason for hiding this comment

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

for 6.1 as it's a new feature

@@ -1306,6 +1311,18 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode, callable $en
->then(static function (array $v): void { throw new InvalidConfigurationException(sprintf('The specified default bus "%s" is not configured. Available buses are "%s".', $v['default_bus'], implode('", "', array_keys($v['buses'])))); })
->end()
->children()
->arrayNode('stop_signals')
->beforeNormalization()
->ifString()->then(static fn (string $value): int => constant($value))
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we check of the constant exists and is a supported signal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if constant doesn't exists - it will return null, and will be caught at validate. About supported signal, it's checked inside the Listeners itself.

@@ -1306,6 +1311,18 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode, callable $en
->then(static function (array $v): void { throw new InvalidConfigurationException(sprintf('The specified default bus "%s" is not configured. Available buses are "%s".', $v['default_bus'], implode('", "', array_keys($v['buses'])))); })
->end()
->children()
->arrayNode('stop_signals')
Copy link
Member

Choose a reason for hiding this comment

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

For lists, you should add fixXmlConfig

@@ -41,6 +41,11 @@
use Symfony\Component\WebLink\HttpHeaderSerializer;
use Symfony\Component\Workflow\WorkflowEvents;

use function array_keys;
use function constant;
Copy link
Member

Choose a reason for hiding this comment

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

do not import functions please.

@@ -192,8 +193,9 @@
->tag('kernel.event_subscriber')
->tag('monolog.logger', ['channel' => 'messenger'])

->set('messenger.listener.stop_worker_on_sigterm_signal_listener', StopWorkerOnSigtermSignalListener::class)
Copy link
Member

Choose a reason for hiding this comment

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

is it a BC break? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isn't that internal service used by framework itself? how can it be BC-break?

@@ -1,5 +1,6 @@
framework:
messenger:
stop_signals: SIGTERM
Copy link
Member

Choose a reason for hiding this comment

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

Agreed with @Warxcell. we should allow multiple signals.

@magnetik
Copy link
Contributor

@Warxcell hi, sorry for the direct ping :)
Are you willing to continue this PR or can someone take this over?

@Warxcell
Copy link
Contributor Author

Yes, sorry. Will try to finish till the end of the week.

@Warxcell Warxcell force-pushed the configurable_stop_signal branch 2 times, most recently from 33341f9 to 8aaa16d Compare March 15, 2022 07:28
@Warxcell Warxcell changed the base branch from 6.0 to 6.1 March 15, 2022 07:30
@Warxcell Warxcell force-pushed the configurable_stop_signal branch 2 times, most recently from 58cd5d6 to dac1bd8 Compare March 15, 2022 07:39
@Warxcell Warxcell force-pushed the configurable_stop_signal branch from dac1bd8 to 2aef839 Compare March 15, 2022 08:43
@Warxcell
Copy link
Contributor Author

Need a little help - one test needs PCNTL extension, and the other don't need it - is this achievable?

@fabpot fabpot modified the milestones: 6.1, 6.2 May 20, 2022
@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@nicolas-grekas nicolas-grekas added this to the 6.4 milestone Nov 15, 2023
@fabpot
Copy link
Member

fabpot commented Apr 8, 2024

Closing in favor of #54510

@fabpot fabpot closed this Apr 8, 2024
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.

[Messenger] Gracefull stop messenger when ran in Docker FPM Image
7 participants