Skip to content
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

Running setup:config:set can crash in certain situations, seems to be bug introduced in Magento 2.4.1 #37409

Closed
1 of 5 tasks
hostep opened this issue Apr 21, 2023 · 10 comments
Closed
1 of 5 tasks
Labels
Area: Framework Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.6 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@hostep
Copy link
Contributor

hostep commented Apr 21, 2023

Preconditions and environment

  • Magento version: 2.4.1-2.4.6, also current 2.4-develop is impacted

Steps to reproduce

  1. Setup clean Magento and fully install it
  2. Open the file app/etc/env.php and search for the correct db username in the db/connection/default/username path
  3. Change the app/etc/env.php file and change the db/connection/default/username to a non-existing database user (using wrong-user in example below)
  4. Run bin/magento setup:config:set -n --db-user=xxx (where you replace xxx with the correct database user you found in step 2)
  5. Inspect the app/etc/env.php file afterwards to see if the username got updated correctly

Expected result

$ bin/magento setup:config:set -n --db-user=xxx
We saved default values for these options: amqp-host, amqp-port, amqp-user, amqp-password, amqp-virtualhost, amqp-ssl, amqp-ssl-options, db-ssl-key, db-ssl-cert, db-ssl-ca, db-ssl-verify, allow-parallel-generation.

$ echo $?
0

$ grep 'username' app/etc/env.php
                'username' => 'xxx',

Actual result

$ bin/magento setup:config:set -n --db-user=xxx
We saved default values for these options: amqp-host, amqp-port, amqp-user, amqp-password, amqp-virtualhost, amqp-ssl, amqp-ssl-options, db-ssl-key, db-ssl-cert, db-ssl-ca, db-ssl-verify, allow-parallel-generation.

In Abstract.php line 144:

  SQLSTATE[HY000] [1045] Access denied for user 'wrong-user'@'localhost' (using password: YES)


In Abstract.php line 128:

  SQLSTATE[HY000] [1045] Access denied for user 'wrong-user'@'localhost' (using password: YES)


$ echo $?
255

$ grep 'username' app/etc/env.php
                'username' => 'xxx',

Additional information

We have a certain workflow where we expect to have a wrong db user in the app/etc/env.php file and expect it to be able to change it without errors using bin/magento setup:config:set

This used to work before Magento 2.4.1, but seems to have been broken ever since Magento 2.4.1, which is kind of annoying for us.

It looks like the config change does work in that command, but the updated configuration isn't being reloaded before it tries to do whatever it crashes on a bit later.

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”.
@m2-assistant
Copy link

m2-assistant bot commented Apr 21, 2023

Hi @hostep. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

@hostep
Copy link
Contributor Author

hostep commented Apr 21, 2023

After a git bisecting session, it seems like the issue was introduced by commit: ec098d2, now to figure out why exactly ...

@hostep
Copy link
Contributor Author

hostep commented Apr 21, 2023

Okay, it has something to do with the class Magento\MediaContentSynchronizationApi\Model\SynchronizerPool.
It gets included through Magento\MediaContentSynchronization\Console\Command\Synchronize which includes Magento\MediaContentSynchronizationApi\Api\SynchronizeInterface which then includes Magento\MediaContentSynchronizationApi\Model\SynchronizerPool

Injecting a proxy of the SynchronizeInterface class into the console command using the di.xml file solves the issue after some quick testing:

diff --git a/app/code/Magento/MediaContentSynchronization/etc/di.xml b/app/code/Magento/MediaContentSynchronization/etc/di.xml
index d4615c15206..100f364b305 100644
--- a/app/code/Magento/MediaContentSynchronization/etc/di.xml
+++ b/app/code/Magento/MediaContentSynchronization/etc/di.xml
@@ -14,6 +14,11 @@
             </argument>
         </arguments>
     </type>
+    <type name="Magento\MediaContentSynchronization\Console\Command\Synchronize">
+        <arguments>
+            <argument name="synchronizeContent" xsi:type="object">Magento\MediaContentSynchronizationApi\Api\SynchronizeInterface\Proxy</argument>
+        </arguments>
+    </type>
     <type name="Magento\MediaGallerySynchronization\Model\Consume">
         <plugin name="synchronize_media_content"
                 type="Magento\MediaContentSynchronization\Plugin\SynchronizeMediaContent"/>

Update: hmm, was testing this on an in-between commit between 2.4.0 and 2.4.1 and that solved the issue, but it didn't solve the issue on 2.4.1 nor 2.4-develop, grmbl, still digging around ...

@hostep
Copy link
Contributor Author

hostep commented Apr 21, 2023

Okay, it was due to yet another command that was added that has the same problem.
A full fix for the 2.4-develop branch is like so:

diff --git a/app/code/Magento/MediaContentSynchronization/etc/di.xml b/app/code/Magento/MediaContentSynchronization/etc/di.xml
index e5347f1a115..ed096340e70 100644
--- a/app/code/Magento/MediaContentSynchronization/etc/di.xml
+++ b/app/code/Magento/MediaContentSynchronization/etc/di.xml
@@ -15,6 +15,11 @@
             </argument>
         </arguments>
     </type>
+    <type name="Magento\MediaContentSynchronization\Console\Command\Synchronize">
+        <arguments>
+            <argument name="synchronizeContent" xsi:type="object">Magento\MediaContentSynchronizationApi\Api\SynchronizeInterface\Proxy</argument>
+        </arguments>
+    </type>
     <type name="Magento\MediaGallerySynchronization\Model\Consume">
         <plugin name="synchronize_media_content"
                 type="Magento\MediaContentSynchronization\Plugin\SynchronizeMediaContent"/>
diff --git a/app/code/Magento/MediaGallerySynchronization/etc/di.xml b/app/code/Magento/MediaGallerySynchronization/etc/di.xml
index 82bd1303eda..2d793825b89 100644
--- a/app/code/Magento/MediaGallerySynchronization/etc/di.xml
+++ b/app/code/Magento/MediaGallerySynchronization/etc/di.xml
@@ -47,6 +47,11 @@
             </argument>
         </arguments>
     </type>
+    <type name="Magento\MediaGallerySynchronization\Console\Command\Synchronize">
+        <arguments>
+            <argument name="synchronizeAssets" xsi:type="object">Magento\MediaGallerySynchronizationApi\Api\SynchronizeInterface\Proxy</argument>
+        </arguments>
+    </type>
     <type name="Magento\Framework\App\Config\Value">
         <plugin name="admin_system_config_adobe_stock_save_plugin" type="Magento\MediaGallerySynchronization\Plugin\MediaGallerySyncTrigger"/>
     </type>

I'll see if I can find some time next week for a PR ...

@engcom-November engcom-November self-assigned this Apr 24, 2023
@m2-assistant
Copy link

m2-assistant bot commented Apr 24, 2023

Hi @engcom-November. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • 5. Add label Issue: Confirmed once verification is complete.
  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@hostep
Copy link
Contributor Author

hostep commented Apr 24, 2023

Found some more time to dig into this, after going through dependencies of dependencies of dependencies, ..., it turned out that this fixes the issue as well:

diff --git a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetEntityContent.php b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetEntityContent.php
index c3766484ce4..9136f245492 100644
--- a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetEntityContent.php
+++ b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetEntityContent.php
@@ -7,7 +7,6 @@ declare(strict_types=1);
 
 namespace Magento\MediaContentCatalog\Model\ResourceModel;
 
-use Magento\Catalog\Model\ResourceModel\Product;
 use Magento\Framework\App\ResourceConnection;
 use Magento\MediaContentApi\Model\GetEntityContentsInterface;
 use Magento\MediaContentApi\Api\Data\ContentIdentityInterface;
@@ -23,11 +22,6 @@ class GetEntityContent implements GetEntityContentsInterface
      */
     private $config;
 
-    /**
-     * @var Product
-     */
-    private $productResource;
-
     /**
      * @var ResourceConnection
      */
@@ -36,15 +30,12 @@ class GetEntityContent implements GetEntityContentsInterface
     /**
      * @param Config $config
      * @param ResourceConnection $resourceConnection
-     * @param Product $productResource
      */
     public function __construct(
         Config $config,
-        ResourceConnection $resourceConnection,
-        Product $productResource
+        ResourceConnection $resourceConnection
     ) {
         $this->config = $config;
-        $this->productResource = $productResource;
         $this->resourceConnection = $resourceConnection;
     }
 
diff --git a/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php b/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php
index eebb172e482..01465eb2b27 100644
--- a/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php
+++ b/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php
@@ -12,7 +12,7 @@ use Magento\Framework\Exception\LocalizedException;
 use Magento\Framework\Filesystem;
 use Magento\Framework\Filesystem\Directory\ReadInterface;
 use Magento\Framework\Filesystem\Driver\File;
-use Magento\Framework\Stdlib\DateTime\DateTime;
+use Magento\Framework\Stdlib\DateTime\DateTimeFactory;
 use Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface;
 use Magento\MediaGallerySynchronizationApi\Model\ImportFilesInterface;
 use Magento\MediaGallerySynchronizationApi\Api\SynchronizeFilesInterface;
@@ -60,14 +60,14 @@ class SynchronizeFiles implements SynchronizeFilesInterface
     private $importFiles;
 
     /**
-     * @var DateTime
+     * @var DateTimeFactory
      */
-    private $date;
+    private $dateFactory;
 
     /**
      * @param File $driver
      * @param Filesystem $filesystem
-     * @param DateTime $date
+     * @param DateTime $dateFactory
      * @param LoggerInterface $log
      * @param GetFileInfo $getFileInfo
      * @param GetAssetsByPathsInterface $getAssetsByPaths
@@ -76,7 +76,7 @@ class SynchronizeFiles implements SynchronizeFilesInterface
     public function __construct(
         File $driver,
         Filesystem $filesystem,
-        DateTime $date,
+        DateTimeFactory $dateFactory,
         LoggerInterface $log,
         GetFileInfo $getFileInfo,
         GetAssetsByPathsInterface $getAssetsByPaths,
@@ -84,7 +84,7 @@ class SynchronizeFiles implements SynchronizeFilesInterface
     ) {
         $this->driver = $driver;
         $this->filesystem = $filesystem;
-        $this->date = $date;
+        $this->dateFactory = $dateFactory;
         $this->log = $log;
         $this->getFileInfo = $getFileInfo;
         $this->getAssetsByPaths = $getAssetsByPaths;
@@ -148,7 +148,7 @@ class SynchronizeFiles implements SynchronizeFilesInterface
      */
     private function getFileModificationTime(string $path): string
     {
-        return $this->date->gmtDate(
+        return $this->dateFactory->create()->gmtDate(
             self::DATE_FORMAT,
             $this->getFileInfo->execute($this->getMediaDirectory()->getAbsolutePath($path))->getMTime()
         );

Both these dependencies made somehow a connection to the database from within their constructor (or dependency parent constructors), and that is really not needed at the time of the constructor.

In case of the $productResource, this member wasn't even used in the class, so it can be removed.
In the case of the DateTime, we can change it to a Factory, the same way as it was done in: https://github.com/magento/magento2/blob/2.4.6/app/code/Magento//MediaContentSynchronization/Model/Synchronize.php#L58

@m2-community-project m2-community-project bot added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Apr 25, 2023
@m2-community-project m2-community-project bot added this to Pull Request In Progress in High Priority Backlog Apr 25, 2023
@m2-community-project m2-community-project bot removed this from Ready for Confirmation in Issue Confirmation and Triage Board Apr 25, 2023
@hostep hostep changed the title Running setup:config:set can crash in certain situations, seems to be bug introduced in Magento 2.4.1 Fix for running bin/magento without proper database connection (removes db connection attempts from DI constructors) Apr 25, 2023
@hostep hostep changed the title Fix for running bin/magento without proper database connection (removes db connection attempts from DI constructors) Running setup:config:set can crash in certain situations, seems to be bug introduced in Magento 2.4.1 Apr 25, 2023
@engcom-November
Copy link
Contributor

Hi @hostep
Thank you for reporting and collaboration. Verified the issue on Magento 2.4-develop instance with below steps followed and the issue is reproducible. Hence confirming the issue.
Steps performed:

  1. Updated DB username in app/etc/env.php file with wrong user name manually. Ex: 'xxxy'

  2. Run the command from cli with correct DB user name: php bin/magento setup:config:set -n --db-user=global
    Issue: SQLSTATE[HY000] [1698] Access denied for user 'xxxy'@'localhost' error message is displayed.
    image

  3. Run the below command again from cli with correct DB user name : php bin/magento setup:config:set -n --db-user='global'
    No issue: No error displayed
    image

  4. Inspect env.php file again and check the db username - Issue: Value is not updated
    image

@engcom-November engcom-November added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Area: Framework Reported on 2.4.6 Indicates original Magento version for the Issue report. labels Apr 27, 2023
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-8607 is successfully created for this GitHub issue.

@m2-assistant
Copy link

m2-assistant bot commented Apr 27, 2023

✅ Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@ihor-sviziev
Copy link
Contributor

The issue was fixed in 4095595 (changes from #37424).
I'm closing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Framework Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.6 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
4 participants