-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Redis session concurrency error not correctly handled (intermittent "Area Code Is Not Set" report) #19207
Comments
Hi @convenient. Thank you for your report.
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
where @convenient do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?
|
To confirm i have replicated this on a vanilla 2.1.15 EE install, although I do not believe that this is related to EE code in any way. |
Hi @engcom-backlog-nazar. Thank you for working on this issue.
|
HI seems like this have been fixed in 2.3-develop -> #17608 now i'm have error |
@engcom-backlog-nazar Agreed. On the 2.3 branch I got a similar sensible report generated. I believe the As magento 2.3 relies on PHP 7.1 or higher it will not be affected. |
@convenient, i'm closing this as this was fixed in 2.3-develop. if someone in future have same issue we can reopen this one. |
@engcom-backlog-nazar Are github issues now only interested in 2.3? I thought 2.2 was still supported until December 2019? |
@convenient i'm just tested on 2.2-dev seems like really this occurs only with php7.0 version, yes 2.2 supported, but this is specified bug, only with specific php version. Maybe leave this open. |
@convenient i am sorry. there is so many threads about session errors and redis, each thread points to the other, that i got lost between all of them. i saw an error report similar to mine few posts above, so i posted here. |
@RaFr no worries, i hope the other thread helps as there won't be much more in this issue to help you out I think :) |
Hi @engcom-backlog-andrii. Thank you for working on this issue.
|
Hi @engcom-Delta. Thank you for working on this issue.
|
Hi @convenient We are not able to reproduce this issue on the lates We are closing this issue due to branch If you still faced this issue on |
The issue is still reproducible. We have encountered a Redis concurrency limit exceeded case and see the "Area code not set" report. |
Possibly fixed in Magento 2.4.7? Which includes this change: 4d223b1 |
Holy moly. They finally did it. Thanks @hostep |
Preconditions
Steps to reproduce
ConcurrentConnectionsExceededException
when loading a web page, instructions for emulating this error are included in the section titled "To emulate locally"Expected result
Actual result
Area code is not set
report is generated. This error is seemingly unrelated making the actual issue hard to diagnose and fix.Notes and explanation
I've spent the last few days debugging a randomly occurring report page.
Through a lot of
file_put_contents
logging I managed to track down the issue. It was that theMagento\Framework\App\State
object which threw the exception was a different instance than the one configured inMagento\Framework\App\Http::launch
which had the area code set. 💥Here's the code journey for how this error can occur, and a way of how to demonstrate it locally. I am referring to code in 2.1.15 but others have seen it in the 2.2 series as well.
TL;DR to fix this error report on your website
Increase your redis
max_concurrency
inapp/etc/env.php
and flush your config cache. It fixed the issue (session locking) for me.To emulate locally
Go into
Cm\RedisSession\Handler
and amendread
to throw the exception.public function read($sessionId) { + throw new ConcurrentConnectionsExceededException();
Load up your homepage and see the
Area Code Is Not Set
report generated.Broken journey explanation
https://github.com/magento/magento2/blob/2.1.15/lib/internal/Magento/Framework/App/Bootstrap.php#L249-L270
The application bootstrap goes through the process of instantiating the object manager, launching the application, and sending the response (or handling errors).
https://github.com/magento/magento2/blob/2.1.15/lib/internal/Magento/Framework/App/Bootstrap.php#L229-L241
This section instantiates the object manager, creates the
Magento\Framework\App\Http
which then createsMagento\Framework\App\State
as a dependency (with no area code set).https://github.com/magento/magento2/blob/2.1.15/lib/internal/Magento/Framework/App/Http.php#L128-L135
The application is launched and the area code is set against the
Magento\Framework\App\State
object. As this is a singleton we should have the area code set for the entirety of the request. The request is thendispatch
ed.https://github.com/magento/magento2/blob/2.1.15/lib/internal/Magento/Framework/Session/SessionManager.php#L167-L189
Now that the request is underway the
SessionManager
will initialise (withsession_start
) and try to read your session information.https://github.com/magento/magento2/blob/2.1.15/lib/internal/Magento/Framework/Session/SaveHandler/Redis.php#L43-L50
This is the section of code which actually tries to read the session. The error here is in the handling of
ConcurrentConnectionsExceededException
, the catch requires theerrors/503.php
page but does not stop the program execution.https://github.com/magento/magento2/blob/2.1.15/pub/errors/503.php#L1-L12
The
errors/503.php
creates an error processor, processes the error, and sends the response.https://github.com/magento/magento2/blob/2.1.15/pub/errors/processorFactory.php#L21-L27
The processor factory creates a new instance of the object manager using the
ObjectManagerFactory
, meaning all shared instances from the previous object manager are no longer relevant for this instance.https://github.com/magento/magento2/blob/2.1.15/lib/internal/Magento/Framework/App/ObjectManagerFactory.php#L182-L183
Even worse, in the background of the
ObjectManagerFactory
it overrides the global reference to the object manager.This means that
State
was created and an area code was set.errors/503.php
was requiredState
because this only occurs in theMagento\Framework\App\Http::launch
functionerrors/503.php
errors/503.php
was required.Proposed code change
Essentially we tried to throw an error, failed, and a different error was triggered from a different part of the application because we had two versions of the object manager in memory.
As far as I can see only two parts of the application require
errors/503.php
in this manner.I propose we pass back the exception from the redis handler to the http app rather than trying to trigger a 503 page manually, this will terminate the request and generate a usable error report.
Let me know your feedback, if this approach is agreed I will raise a PR.
The text was updated successfully, but these errors were encountered: