magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.5k stars 9.3k forks source link

Admin got auto logged out when product reviews data is more than 28,000 at Marketing > All Reviews #38198

Open farhanramliwowshop opened 10 months ago

farhanramliwowshop commented 10 months ago

Preconditions and environment

{
    "name": "magento/project-enterprise-edition",
    "description": "eCommerce Platform for Growth (Enterprise Edition)",
    "type": "project",
    "license": [
        "proprietary"
    ],
    "config": {
        "allow-plugins": {
            "dealerdirect/phpcodesniffer-composer-installer": true,
            "laminas/laminas-dependency-plugin": true,
            "magento/*": true
        },
        "preferred-install": "dist",
        "sort-packages": true
    },
    "version": "2.4.4-p4",
    "require": {
        "magento/composer-dependency-version-audit-plugin": "~0.1",
        "magento/composer-root-update-plugin": "~2.0",
        "magento/module-bundle-sample-data": "100.4.*",
        "magento/module-catalog-rule-sample-data": "100.4.*",
        "magento/module-catalog-sample-data": "100.4.*",
        "magento/module-cms-sample-data": "100.4.*",
        "magento/module-configurable-sample-data": "100.4.*",
        "magento/module-customer-balance-sample-data": "100.4.*",
        "magento/module-customer-sample-data": "100.4.*",
        "magento/module-downloadable-sample-data": "100.4.*",
        "magento/module-gift-card-sample-data": "100.4.*",
        "magento/module-gift-registry-sample-data": "100.4.*",
        "magento/module-grouped-product-sample-data": "100.4.*",
        "magento/module-msrp-sample-data": "100.4.*",
        "magento/module-multiple-wishlist-sample-data": "100.4.*",
        "magento/module-offline-shipping-sample-data": "100.4.*",
        "magento/module-product-links-sample-data": "100.4.*",
        "magento/module-review-sample-data": "100.4.*",
        "magento/module-sales-rule-sample-data": "100.4.*",
        "magento/module-sales-sample-data": "100.4.*",
        "magento/module-swatches-sample-data": "100.4.*",
        "magento/module-target-rule-sample-data": "100.4.*",
        "magento/module-tax-sample-data": "100.4.*",
        "magento/module-theme-sample-data": "100.4.*",
        "magento/module-widget-sample-data": "100.4.*",
        "magento/module-wishlist-sample-data": "100.4.*",
        "magento/product-enterprise-edition": "2.4.4-p2",
        "magento/sample-data-media": "100.4.*",
        "mageplaza/module-smtp": "^4.7"
    },
    "autoload": {
        "exclude-from-classmap": [
            "**/dev/**",
            "**/update/**",
            "**/Test/**"
        ],
        "files": [
            "app/etc/NonComposerComponentRegistration.php"
        ],
        "psr-0": {
            "": [
                "app/code/",
                "generated/code/"
            ]
        },
        "psr-4": {
            "Magento\\": "app/code/Magento/",
            "Magento\\Framework\\": "lib/internal/Magento/Framework/",
            "Magento\\Setup\\": "setup/src/Magento/Setup/"
        }
    },
    "require-dev": {
        "allure-framework/allure-phpunit": "~1.5.0",
        "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
        "friendsofphp/php-cs-fixer": "~3.3.0",
        "lusitanian/oauth": "~0.8.10",
        "magento/magento-coding-standard": "*",
        "magento/magento2-functional-testing-framework": "^3.7",
        "pdepend/pdepend": "~2.10.0",
        "phpmd/phpmd": "^2.9.1",
        "phpstan/phpstan": "~1.2.0",
        "phpunit/phpunit": "~9.5.0",
        "sebastian/phpcpd": "^6.0.3",
        "squizlabs/php_codesniffer": "~3.6.0",
        "symfony/finder": "^5.2"
    },
    "conflict": {
        "gene/bluefoot": "*"
    },
    "autoload-dev": {
        "psr-4": {
            "Magento\\PhpStan\\": "dev/tests/static/framework/Magento/PhpStan/",
            "Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/",
            "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/",
            "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/TestFramework/Utility/",
            "Magento\\Tools\\": "dev/tools/Magento/Tools/",
            "Magento\\Tools\\Sanity\\": "dev/build/publication/sanity/Magento/Tools/Sanity/"
        }
    },
    "minimum-stability": "stable",
    "prefer-stable": true,
    "repositories": [
        {
            "type": "composer",
            "url": "https://repo.magento.com/"
        }
    ],
    "extra": {
        "magento-force": "override"
    }
}

require DIR . '/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $appState = $objectManager->get('Magento\Framework\App\State'); $appState->setAreaCode('frontend');

$reviewFactory = $objectManager->get(ReviewFactory::class); $ratingFactory = $objectManager->get(RatingFactory::class); $productFactory = $objectManager->get(ProductFactory::class); $resource = $objectManager->get(ResourceConnection::class);

// Get a random product ID $productIds = $productFactory->create()->getCollection()->getAllIds(); $productId = $productIds[array_rand($productIds)];

// Get a random customer ID $customerIds = $objectManager->create('Magento\Customer\Model\Customer')->getCollection()->getAllIds(); $customerId = $customerIds[array_rand($customerIds)];

$randValue = rand(1, 99999999999999);

// Create a random review title and detail $randomTitle = "Review Title " . $randValue; $randomDetail = "Review Detail " . $randValue; $randomNickname = "Farhan " . $randValue;

// Create a review $review = $reviewFactory->create(); $review->setEntityPkValue($productId); $review->setStatusId(\Magento\Review\Model\Review::STATUS_APPROVED); $review->setTitle($randomTitle); $review->setDetail($randomDetail); $review->setEntityId(1); // 1 corresponds to the product entity type $review->setStoreId(1); // Replace with your store ID $review->setStores([1]); // Replace with your store IDs

// Assign random ratings $ratings = [ 'quality' => rand(1, 5), 'price' => rand(1, 5), 'value' => rand(1, 5), ]; $review->setRatings($ratings);

$review->setCustomerId($customerId); $review->setNickname($randomNickname); $review->save();

echo "Review added successfully.\n";

- Run the script above through command line by entering this command in root directory `php add_reviews.php`
- To create up to 28000 data run this command `for i in {1..28000}; do php add_reviews.php; done`

### Steps to reproduce

1. Make sure you already satisfy the precondition above to have added up to 28,000 or more product review data into your magento database
2. Login into magento admin panel as Administrator or any other admin user that has access to Marketing > All Reviews
3. Navigate to Marketing > All Reviews ( under User Content)
4. After reaching the All Review page, try to navigate anywhere or refresh the page
5. You will realize that you automatically got logged out

### Expected result

Admin user should not get auto logged out and able to navigate anywhere as usual , able to edit the product review in the all review page

### Actual result

Admin user get auto logged out, log is as follows

[2023-11-17T08:08:26.832487+00:00] report.WARNING: Session size of 2413109 exceeded allowed session max size of 256000. [] []



The issue from what seen is because of session overload and because of that magento auto logged out the admin user

### Additional information

_No response_

### 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._
- [X] 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[bot] commented 10 months ago

Hi @farhanramliwowshop. 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:

qlhu commented 10 months ago

It's reproducible in 2.4.5-p5. The root cause is getResultingIds() of https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Review/Model/ResourceModel/Review/Product/Collection.php. It resets the query to pull all reviews from database and then utilize the results to build edit link. My workaround is to create a patch to update it like below.

$data = $this->getConnection() ->fetchAll( $idsSelect ->columns('rt.review_id') );

m2-assistant[bot] commented 10 months ago

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: :point_down:

engcom-November commented 10 months ago

Hello @farhanramliwowshop,

Thank you for the report and collaboration!

We were able to verify this issue on 2.4-develop. We used your script to add the reviews. In our case the admin page was getting logged out when refreshing the reviews page for 14,500 reviews, with the below error.

[2023-11-30T08:39:16.082220+00:00] main.WARNING: Session size of 276374 exceeded allowed session max size of 256000. [] []

Hence confirming the issue.

Thank you.

github-jira-sync-bot commented 10 months ago

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

m2-assistant[bot] commented 10 months ago

:white_check_mark: 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.

farhanramliwowshop commented 10 months ago

Hi @qlhu, I am able to implement the fix using the code given by you, thank you so much, my test so far on my local environment is working, will update if encountered this issue on other environment

monteshot commented 5 months ago

Product attribute also affected(huge amount of the options) To debug, put the conditional breakpoint at vendor/magento/framework/Session/SessionManager.php:151 image with condition

strpos(strtolower($method), 'set') !==false

This is only produced if you have an exception during the save attribute image