Skip to content

Exit as late as possible #26012

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
Feb 11, 2018
Merged

Exit as late as possible #26012

merged 1 commit into from
Feb 11, 2018

Conversation

greg0ire
Copy link
Contributor

@greg0ire greg0ire commented Feb 1, 2018

People might want to register other shutdown functions that should be
able to control the exit code themselves, without the deprecation error
handler taking over. The php manual says:

If you call exit() within one registered shutdown function, processing
will stop completely and no other registered shutdown functions will be
called.

See https://secure.php.net/manual/en/function.register-shutdown-function.php

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

@greg0ire
Copy link
Contributor Author

greg0ire commented Feb 1, 2018

@alcaeus please review

@@ -151,7 +151,9 @@ public static function register($mode = false)
}

if ('weak' !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) {
exit(1);
register_shutdown_function(function () {
Copy link
Member

@nicolas-grekas nicolas-grekas Feb 2, 2018

Choose a reason for hiding this comment

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

what would be even better would be to defer the whole closure, so that deprecations triggered at shutdown time are also caught (and add a related test of course :) )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The downside being that if a shutdown function uses exit and the whole closure is deferred too, then you won't get any deprecations. But I think catching shutdown time deprecations might outweight this, what do you think? If we want to go crazy, we may even reset the state after the first, non deferred display and if any deprecations are caught while shutting down, then display them in the deferred closure.

Copy link
Member

@nicolas-grekas nicolas-grekas Feb 2, 2018

Choose a reason for hiding this comment

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

as you want, both are fine to me :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll see what I can manage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ended up "going crazy", tell me what you think

@chalasr chalasr added this to the 2.7 milestone Feb 2, 2018
@greg0ire
Copy link
Contributor Author

greg0ire commented Feb 3, 2018

Best reviewed when ignoring whitespace

@nicolas-grekas the second commit feels more like a feature than a bugfix to me. Would you be ok with moving it to a separate PR?


1x: root deprecation

Deprecations during shutdown
Copy link
Contributor Author

@greg0ire greg0ire Feb 3, 2018

Choose a reason for hiding this comment

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

Please tell me if you want more emphasis here and how it should look like (ascii underline with = signs, maybe?), and if I should also add some header for the previous section.

Copy link
Member

Choose a reason for hiding this comment

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

not more than existing titles, so as is LGTM

}

register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations) {
if (array_sum(array_filter($deprecations, function ($key) {
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 calls for a data structure refactoring

Copy link
Member

Choose a reason for hiding this comment

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

let's do a code-style fix for now :) the "if" should be on one line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"fixed" :P

echo "Deprecations during shutdown\n";
}
$displayDeprecations($deprecations);
if ($isFailing) {
Copy link
Member

Choose a reason for hiding this comment

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

if there are shutdown-time deprecations, shouldn't this fail also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@alcaeus
Copy link
Contributor

alcaeus commented Feb 4, 2018

the second commit feels more like a feature than a bugfix to me

TBH, I'd still consider it a bugfix: the original bug was that any existing deprecations cause other shutdown handlers to be ignored. This is fixed in your first commit. Fixing that bug exposes another bug, namely that any deprecations happening in other shutdown handlers don't reported. This is fixed in your second commit.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(failures should be fixed once merged up to master, isn't it?)

@greg0ire
Copy link
Contributor Author

greg0ire commented Feb 4, 2018

Correct, but let me try to test it on 5.4 to be 100% sure.

@greg0ire
Copy link
Contributor Author

greg0ire commented Feb 4, 2018

Don't merge, I get this, which seems to be a bug since I used the same version as in Travis:

Fatal error: Class 'PHPUnit_Util_ErrorHandler' not found in /tmp/sf/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php on line 54

Then, with a var_dump($msg) on the offending line, this:

"Use of undefined constant ARRAY_FILTER_USE_KEY - assumed 'ARRAY_FILTER_USE_KEY'"

This can't work for php < 5.6

@greg0ire
Copy link
Contributor Author

greg0ire commented Feb 4, 2018

I fixed it however I could, it should be good to merge now (although Travis is still red)

@greg0ire
Copy link
Contributor Author

greg0ire commented Feb 4, 2018

Why exactly do we have those Count indices, BTW? I suppose the answer is performance, somehow?

@greg0ire
Copy link
Contributor Author

greg0ire commented Feb 4, 2018

Tested with docker run -it -v $PWD:/tmp/sf squallcx/docker-php54-apache /bin/sh

register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) {
foreach ($deprecations as $group => $arrayOrInt) {
if (is_int($arrayOrInt) && $arrayOrInt > 0 || is_array($arrayOrInt) && count($arrayOrInt) > 0) {
echo "Deprecations during shutdown\n";
Copy link
Member

Choose a reason for hiding this comment

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

Small tweak: s/Deprecations during shutdown/Shutdown-time deprecations:/

People might want to register other shutdown functions that should be
able to control the exit code themselves, without the deprecation error
handler taking over. The php manual says:

> If you call exit() within one registered shutdown function, processing
> will stop completely and no other registered shutdown functions will be
> called.

See https://secure.php.net/manual/en/function.register-shutdown-function.php
@nicolas-grekas
Copy link
Member

Thank you @greg0ire.

@nicolas-grekas nicolas-grekas merged commit 97370a3 into symfony:2.7 Feb 11, 2018
nicolas-grekas added a commit that referenced this pull request Feb 11, 2018
This PR was merged into the 2.7 branch.

Discussion
----------

Exit as late as possible

People might want to register other shutdown functions that should be
able to control the exit code themselves, without the deprecation error
handler taking over. The php manual says:

> If you call exit() within one registered shutdown function, processing
> will stop completely and no other registered shutdown functions will be
> called.

See https://secure.php.net/manual/en/function.register-shutdown-function.php

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

<!--
- Bug fixes must be submitted against the lowest branch where they apply
  (lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the master branch.
- Replace this comment by a description of what your PR is solving.
-->

Commits
-------

97370a3 [Bridge\PhpUnit] Exit as late as possible
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.

5 participants