magento2: [2.4.6-p2] Regression, can trigger error 'Connection "default" is not defined' again
Preconditions and environment
- Magento version 2.4.6-p2 (pre-release which isn’t available on github here yet) but can also be reproduced on
2.4-develop
Steps to reproduce
- Setup a clean Magento
- Ensure there is a file
app/etc/config.php
- Remove the file
app/etc/env.php
- <del>Make sure you empty the current database, it should hold no data or structure (this might be optional, I haven’t checked with an existing database)</del> (Update: confirmed that database doesn’t need to be emptied)
- Run:
# replace the db parameters with the ones from your own database
./bin/magento setup:install \
--admin-firstname=Firstname \
--admin-lastname=Lastname \
--admin-email=email@example.com \
--admin-user=admin \
--admin-password=admin124 \
--base-url=https://url.example/ \
--base-url-secure=https://url.example/ \
--backend-frontname=admin \
--db-host={dbhost} \ # your db host
--db-name={dbname} \ # your db name
--db-user={dbuser} \ # your db user
--db-password={dbpass} \ # your db user's password
--language=en_US \
--currency=EUR \
--timezone=Europe/Brussels \
--use-rewrites=1 \
--use-secure=1 \
--use-secure-admin=1 \
--admin-use-security-key=1 \
--session-save=files \
--cleanup-database \
-vvv
Expected result
Works without issues
Actual result
Getting
...
[Progress: 861 / 864]
Disabling Maintenance Mode:
In ResourceConnection.php line 162:
[DomainException]
Connection "default" is not defined
Exception trace:
at lib/internal/Magento/Framework/App/ResourceConnection.php:162
Magento\Framework\App\ResourceConnection->getConnectionByName() at generated/code/Magento/Framework/App/ResourceConnection/Interceptor.php:41
Magento\Framework\App\ResourceConnection\Interceptor->getConnectionByName() at lib/internal/Magento/Framework/App/ResourceConnection.php:111
Magento\Framework\App\ResourceConnection->getConnection() at generated/code/Magento/Framework/App/ResourceConnection/Interceptor.php:23
Magento\Framework\App\ResourceConnection\Interceptor->getConnection() at lib/internal/Magento/Framework/Model/ResourceModel/Db/AbstractDb.php:312
Magento\Framework\Model\ResourceModel\Db\AbstractDb->getConnection() at app/code/Magento/MessageQueue/Model/ResourceModel/Lock.php:103
Magento\MessageQueue\Model\ResourceModel\Lock->releaseOutdatedLocks() at app/code/Magento/MessageQueue/Model/Plugin/ResourceModel/Lock.php:39
Magento\MessageQueue\Model\Plugin\ResourceModel\Lock->afterSet() at lib/internal/Magento/Framework/Interception/Interceptor.php:146
Magento\Framework\App\MaintenanceMode\Interceptor->Magento\Framework\Interception\{closure}() at lib/internal/Magento/Framework/Interception/Interceptor.php:153
Magento\Framework\App\MaintenanceMode\Interceptor->___callPlugins() at generated/code/Magento/Framework/App/MaintenanceMode/Interceptor.php:32
Magento\Framework\App\MaintenanceMode\Interceptor->set() at setup/src/Magento/Setup/Model/Installer.php:1503
Magento\Setup\Model\Installer->setMaintenanceMode() at n/a:n/a
call_user_func_array() at setup/src/Magento/Setup/Model/Installer.php:388
Magento\Setup\Model\Installer->install() at setup/src/Magento/Setup/Console/Command/InstallCommand.php:238
Magento\Setup\Console\Command\InstallCommand->execute() at vendor/symfony/console/Command/Command.php:298
Symfony\Component\Console\Command\Command->run() at vendor/symfony/console/Application.php:1040
Symfony\Component\Console\Application->doRunCommand() at vendor/symfony/console/Application.php:301
Symfony\Component\Console\Application->doRun() at lib/internal/Magento/Framework/Console/Cli.php:116
Magento\Framework\Console\Cli->doRun() at vendor/symfony/console/Application.php:171
Symfony\Component\Console\Application->run() at bin/magento:23
Additional information
This problem does not occur with Magento 2.4.6-p1, so this is a regression bug. Issue is most likely to happen in CI pipelines, to run integration tests, or whatever else needs a database.
This can be solved
- by removing the
app/etc/config.php
before runningbin/magento setup:install
(but that can lead to other problems) - by running
bin/magento setup:install
twice (where you account for the first one to fail, the first execution will generate aenv.php
file, so the second run can load this config in memory)
This bug has something to do with these changes that were added in Magento 2.4.6-p2: ACP2E-1958: avoid reloading configs for each requested key (cc @bubasuma & @o-iegorov)
It has something to do with trying to fetch the configuration for key db
which it doesn’t find, because it has only loaded the config from config.php
file and not from the env.php
file. So most likely once the db configuration is written to env.php
file, it’s not being refreshed in memory and leads to this problem.
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 24 (17 by maintainers)
Commits related to this issue
- Fix 2.4.6-p2 Workaround for https://github.com/magento/magento2/issues/37805#issuecomment-1658555063 — committed to AmpersandHQ/magento-docker-test-instance by convenient a year ago
@alzota: please don’t close issues without leaving feedback about which commit(s) fixed it.
Can you provide these? Thanks!
@hostep @convenient Internal team is already working on the issue.
In our cases we see this as part of the process of running the integration tests, this is because the integration tests need to run
setup:install
under the hood.I’ve distilled what we do into this (super hacky) script that reproduces the issue.
When I set
MAGE_MODE=2.4.6
the integration tests run fine.When I set
MAGE_MODE=2.4.6-p2
it fails withReproduction script and usage
It’s not a great script but it does repro for me. Using
MYSQL_PORT
andMYSQL_HOST
(edit at top of script)MAGE_VERSION='2.4.6-p2'
can be swapped aroundThis script will create a
rm -rf
and create a subdirbroken-magento-install
from the place you’re running it.@hostep fix is implemented, but not merged yet. Will come back with a commit id on this issue once the fix is merged. Thank you!
Hi @hostep ,
Thanks for Contribution and collaboration!
Verified the issue in 2.4-develop instance as per your last comments and issue can be reproducible,Hence we confirming the issue.Kindly refer the below screenshot:
@hostep @engcom-Charlie I think we should add some automated test coverage for such case to prevent such regressions in the future
Today, after trying out the commit mentioned above, I can confirm that it fixes this issue for us. Thanks for the quick solution guys!
Thanks for confirming @alzota, that means we can close this ticket!
@hostep indeed that is the fix.
Here is a patch with a workaround to get the integration tests running again until a proper fix is released:
Fully agree with @ihor-sviziev
I think its weird that my automated testing which covers the following flakes periodically as new versions of magento are released, seems like it would be trivial enough to set up internally within adobe.
@hostep thanks for confirmation. the label “Progress: PR in progress” made me assume that you might be working on it, that’s why I wanted to confirm.
@alzota: what do you mean? I’m not working on this issue, did I say I would maybe?
I see a label got added
Progress: PR in progress
but I have no idea why or how?