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

Skip to content

[Http-Kernel] [Cache] Warning on deploy with empty cache #36472

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
PatchRanger opened this issue Apr 17, 2020 · 13 comments
Closed

[Http-Kernel] [Cache] Warning on deploy with empty cache #36472

PatchRanger opened this issue Apr 17, 2020 · 13 comments

Comments

@PatchRanger
Copy link
Contributor

Symfony version(s) affected: 5.0.7

Description
Each time on deploy, I keep receiving such warning:

Warning: include(.../releases/191/var/cache/prod/App_KernelProdContainer.php): failed to open stream: No such file or directory

How to reproduce
I have Symfony installation with default cache settings. It happens every deploy. So I guess it's enough to just make Symfony bootstrap with cold cache.

Possible Solution
The root and reason is in "include" without suppressing warning as several lines above.
I am going to create PR to fix it.
According to #25999 (comment) as stated in #26158 (comment) , I am going to replace file_exists with the trick of suppressing warning on include as in https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/Kernel.php#L431 , turning it into the reusable method.

Additional context

if (!flock($lock, $wouldBlock ? LOCK_SH : LOCK_EX)) {
fclose($lock);
$lock = null;
} elseif (!\is_object($this->container = include $cachePath)) {
$this->container = null;
} elseif (!$oldContainer || \get_class($this->container) !== $oldContainer->name) {
flock($lock, LOCK_UN);
fclose($lock);
$this->container->set('kernel', $this);
return;
}

Looks like regression of: #27234 .

PatchRanger added a commit to PatchRanger/symfony that referenced this issue Apr 17, 2020
@nicolas-grekas
Copy link
Member

The error is silenced L432, see

$errorLevel = error_reporting(E_ALL ^ E_WARNING);

It should thus not be reported. Why is it?

PatchRanger added a commit to PatchRanger/symfony that referenced this issue Apr 17, 2020
PatchRanger added a commit to PatchRanger/symfony that referenced this issue Apr 17, 2020
@PatchRanger
Copy link
Contributor Author

@nicolas-grekas You're right - but there is another include, L458 (see in "Additional context"). To that line it could be "unsilenced", as the trick you mentioned applied only for the 1st include.

@PatchRanger
Copy link
Contributor Author

PatchRanger commented Apr 17, 2020

@nicolas-grekas I found the reason: I have error_reporting(E_ALL); in the begin of my index.php - so restoring the value makes it to avoid suppressing this warning.
I guess it's still a bug and should be fixed by suppressing warning only around includes.

@PatchRanger
Copy link
Contributor Author

PatchRanger commented Apr 17, 2020

@nicolas-grekas Still answering your question)) According to docs, error_reporting is ignored in case if there is set_error_handler: https://www.php.net/manual/en/function.set-error-handler.php . It's my case: I have Sentry bundle installed, which obviously uses set_error_handler.
So the problem is that our way of silencing this warning is not silencing in case if you have error-reporting tools enabled (or enabled set_error_handler for another reason).
UPD I am going to debug how Sentry uses set_error_handler, I think it should respect changes of error_reporting. Regarding this open issue: I still think the PR is correct and should be merged - though it doesn't fix this particular issue but makes how we work with error_reporting more precise and accurate.

@nicolas-grekas
Copy link
Member

Closing as this has been identified as an issue on Sentry's side.
Note that I would advise not using Sentry's ErrorHandler in any Symfony app. Sentry should be wired as a monolog handler instead.

@Jean85
Copy link
Contributor

Jean85 commented Apr 20, 2020

Note that I would advise not using Sentry's ErrorHandler in any Symfony app. Sentry should be wired as a monolog handler instead.

Could you elaborate on the reasons behind this, @nicolas-grekas? Since now I've preferred wiring Sentry in the bundle through the error handler since it's natively present from the base SDK, and the handler is designed taking inspiration from Symfony's.

The Monolog approach seemed fragile in the past, since I would have to rely on a secondary bundle (MonologBundle) to work; also, I'm not sure I would be able to collect some collateral info; not sure about this last point, I need to reevaluate now.

@nicolas-grekas
Copy link
Member

@Jean85 sure, let me try:

The error handler is a global piece of non-trivial code. I would expect all Symfony apps to behave exactly the same no matter whether there is a bug catcher around (Sentry, Bugsnag, etc). When there is a bug catcher, I would expect it to not change any global state - that's too tricky, especially when there is already a stack in place. Since Symfony already has this stack for handling errors, I would expect bug catchers to standardize on reusing it when used within a Symfony app. If you need one example of how this can go wrong, this very issue is the example. By definition, the Symfony stack is more proven (since it runs on apps that don't have Sentry). It can be trusted more. The conclusion is that: don't hook here Sentry.

Then:

The Monolog approach seemed fragile in the past, since I would have to rely on a secondary bundle (MonologBundle) to work;

If you want the bundle to be useful without Monolog bundle, I would recommend you to provide Sentry as a PSR-3 logger then. But when Monolog is installed, it should be leveraged, as it allows more powerful setups (e.g with the finger-crossed handler, etc.) But I wouldn't be shocked if monolog-bundle would be a dependency of sentry-bundle. Monolog is also more widely used than sentry-bundle - requiring it would satisfy the package principles.

I would be able to collect some collateral info; not sure about this last point, I need to reevaluate now.

I don't think you'd miss any info, but please report back if you find any of course.

@Jean85
Copy link
Contributor

Jean85 commented Apr 20, 2020

Luckily PSR-3 handler is already present in the base SDK, so that option is already covered: if a user wants that, just skip the bundle. The bundle should just be a fast way to install Sentry with a nice out-of-the-box experience in a Symfony app.

I could try to change the hook, only downside that I see is that requiring explicitly the Monolog bundle is a no-go, because I would "silently" install it for the user. So I thought of a different approach: what do you think about hooking the PSR-3 handler directly to the Symfony error handler? I see that it has already some logger support there...

Otherwise, I could detect the presence of the bundle and act accordingly, but I would have to fall back to the current approach if Monolog is absent..

@nicolas-grekas
Copy link
Member

Otherwise, I could detect the presence of the bundle and act accordingly, but I would have to fall back to the current approach if Monolog is absent..

That should be the way to go then I think.

@nicolas-grekas
Copy link
Member

Loosely related: I would recommend sentry-bundle to use the symfony http-client by default also :)
I'd better have monolog-bundle as a dep than guzzle :)

@ste93cry
Copy link
Contributor

Luckily PSR-3 handler is already present in the base SDK

@Jean85 No PSR-3 handler is provided from getsentry/sentry at the moment 😉

Otherwise, I could detect the presence of the bundle and act accordingly, but I would have to fall back to the current approach if Monolog is absent..

If we decorate the logger service so that it logs to Sentry too it will work with and without Monolog, but it could introduce a problem if someone then uses the same logger inside Sentry itself. We should prevent this somehow or add some notes to the documentation

@Jean85
Copy link
Contributor

Jean85 commented Apr 21, 2020

@Jean85 No PSR-3 handler is provided from getsentry/sentry at the moment wink

We do have this: https://github.com/getsentry/sentry-php/blob/master/src/Monolog/Handler.php

If we decorate the logger service so that it logs to Sentry too it will work with and without Monolog, but it could introduce a problem if someone then uses the same logger inside Sentry itself. We should prevent this somehow or add some notes to the documentation

That's too generic and risky IMHO. I would stick to the previous suggested approach.

Loosely related: I would recommend sentry-bundle to use the symfony http-client by default also :)
I'd better have monolog-bundle as a dep than guzzle :)

The bundle doesn't have a direct dep, and the base library relies on PSR-18. Guzzle is just the out-of-the-box suggestion, you can change it anytime. Also, to use the Symfony client I would have to drop support for Symfony < 4.3, so maybe I could consider that in the future.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 21, 2020

to use the Symfony client I would have to drop support for Symfony < 4.3

actually, since you already have php 7.1 as a minimum dependency, and since the http-client component is standalone, this can be used even if the rest of the stack is using mostly previous versions of Symfony components.

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

No branches or pull requests

5 participants