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

\Klaviyo\Reclaim\Plugin\Api\CartSearchRepository::afterGetList Infinite Loop #133

Closed
pmclain opened this issue Aug 28, 2021 · 7 comments · Fixed by magento/magento2#33324

Comments

@pmclain
Copy link

pmclain commented Aug 28, 2021

Steps to reproduce

All cart interactions below should be done via API

  1. Create cart
  2. Add at least one product to cart
  3. Apply coupon code to cart (must be a code)
  4. Edit the cart product in the admin panel
  5. Reload cart

Expected Result

/rest/{{store}}/V1/carts/mine should return your cart ID

Actual Result

An infinite loop is triggered when a quote has quote.coupon_code <> NULL AND quote.trigger_recollect = 1

Summarizing the call stack triggered by this combination:

$maskedId = $this->getMaskedIdFromQuoteId($quote->getId());

https://github.com/magento/magento2/blob/ab815b51dad2a89b120cc53b26eefaee80a336f3/app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php#L53

https://github.com/magento/magento2/blob/ab815b51dad2a89b120cc53b26eefaee80a336f3/app/code/Magento/Quote/Model/QuoteRepository.php#L136

https://github.com/magento/magento2/blob/ab815b51dad2a89b120cc53b26eefaee80a336f3/app/code/Magento/Quote/Model/Quote.php#L2461

☝️ Recollection is triggered here because editing a product in the quote sets quote.trigger_recollect = 1

During recollection https://github.com/magento/magento2/blob/ab815b51dad2a89b120cc53b26eefaee80a336f3/app/code/Magento/SalesRule/Observer/CouponCodeValidation.php#L66
validates the coupon code. The validation calls CartRepositoryInterface::getList which re-triggers your plugin.

$found = $this->cartRepository->getList(
  $this->criteriaBuilder->addFilter('main_table.' . CartInterface::KEY_ENTITY_ID, $quote->getId())
    ->create()
)->getItems();

At this point the request is infinitely looping until it timeouts or exhausts memory.

@klaviyojad
Copy link
Contributor

@pmclain I am seeing that this issue has been logged by @ihor-sviziev here which leads me to think its a magento issue. I will check if the latest version 2.4.3 it is fixed

@ihor-sviziev
Copy link
Contributor

@pmclain, please apply patch from the following PR:
magento/magento2#33324
It's not merged, so definitely not available in any release

@pmclain
Copy link
Author

pmclain commented Sep 1, 2021

I'm surprised Klaviyo's stance on the issue is "not our problem" considering the critical level of impact. Pointing your merchants to a possible fix in core Magento with a TBD release while your module cripples checkout is disappointing.

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Sep 1, 2021

@pmclain I think klaviyo might introduce the workaround (hack against the issue in the core), but the changes should be similar to what I created - fetch the masked quote using direct queries, but not preventing of re calculation of something. Otherwise, we might see some not clear/random issues

@pmclain
Copy link
Author

pmclain commented Sep 1, 2021

@ihor-sviziev I don't care what the fix looks like as long as it's fixed. We've already hotfixed this in our instances. It wound up costing a significant drop in conversion since a rolling ~10% of carts were left in a broken state after upgrading from v2 to v3.

@ihor-sviziev
Copy link
Contributor

@klaviyojad, that's pretty strong argument for introducing a workaround for this issue inside the klaviyo extension.

PS: we had this issue on the cart requests from Klaviyo and it was causing huge cpu on web nodes and db load, but seems like you had it on the frontend, which is more critical

@klaviyojad
Copy link
Contributor

@pmclain apologies for the back and forth on this issue. We have added the changes to version 3.0.8 to handle it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants