Skip to content

Possible Memory Leak in GetProductSalableQtyInterface #38546

Open
@singhalavi

Description

@singhalavi

Preconditions and environment

  • Magento version
    Checked in 2.4.3 and 2.4.6 versions, reproducible in both
  • Anything else that would help a developer reproduce the bug
    Have around 20k Simple products

Steps to reproduce

Step 1: Fetch Products in batches (using limit and offset)
Step 2: Iterate over the products
Step 3: Fetch SalableQty using GetProductSalableQtyInterface
Step 4: Record the peak memory usage using memory_get_peak_usage(). Observe that the peak memory usage increases slowly after every batch.

Comment out the calls to GetProductSalableQtyInterface and repeat steps 1-4. Observe that the peak memory usage remains the same.

Expected result

Peak Memory used should not increase consistently and should stabilize after few batches.

Actual result

Peak memory increases slowly and ultimately it goes OOM.

Additional information

Example Code

// $productCollectionFactory -> CollectionFactory
// $stockByWebsiteIdResolver -> StockByWebsiteIdResolverInterface
// $getProductSalableQtyInterface -> GetProductSalableQtyInterface

 public function processInventory()
    {
        $collection = $this->productCollectionFactory->create();
        $collection->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', ProductType::TYPE_SIMPLE)
            ->addStoreFilter($storeId)
            ->setStoreId($storeId);

        $offset = 0;
        $limit = 200;
        do {
            $products = $collection
                ->getSelect()
                ->order(new \Zend_Db_Expr('e.updated_at desc'))
                ->limit($limit, $offset);
            $offset += $limit;
            if (empty($products)) {
                break;
            }
            foreach ($products as $product) {
                $websiteId = (int)$product->getStore()->getWebsiteId();
                $stockId = $this->stockByWebsiteIdResolver->execute($websiteId)->getStockId();
                $qty = $this->getProductSalableQtyInterface->execute(
                    $product->getSku(),
                    $stockId
                );
            }
            gc_collect_cycles();
            echo "Peak Mem ". memory_get_peak_usage() ;
        } while (true);
    }

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”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FrameworkComponent: InventoryIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Progress: ready for devReported on 2.4.6Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions