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

ProductRepository sku cache is corrupted when cacheLimit is reached #11537

Merged
merged 1 commit into from
Oct 19, 2017
Merged

ProductRepository sku cache is corrupted when cacheLimit is reached #11537

merged 1 commit into from
Oct 19, 2017

Conversation

heldchen
Copy link
Contributor

@heldchen heldchen commented Oct 18, 2017

Numeric SKUs are renumbered when array_slice is used to purge parts of the products-by-sku cache array. Per php documentation:

Note that array_slice() will reorder and reset the numeric array indices by default.

PHP considers numeric-looking values like '123' as numeric even when used as array indices. so although the $product->getSku() returns a string, the string might still look like a number and is then renumbered during array_slice.

as $this->instances has the SKUs as keys, the resulting shortened array might contain indexes that now point to a wrong product, which can lead to the ProductRespository returning the wrong product for a given SKU.

Description

Manual testing scenarios

load >1000 products by sku, where the skus are numeric via $productRepository->get($sku);, then observe the $productRepository->instance array

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

Nummeric SKUs are renumbered when array_slice is used to purge parts of the products-by-sku cache array. Per php documentation:
> Note that array_slice() will reorder and reset the numeric array indices by default. 

as `$this->instances` has the SKUs as keys, the resulting shortened array might contain indexes that now point to a wrong product.
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Oct 18, 2017

CLA assistant check
All committers have signed the CLA.

@heldchen heldchen changed the title ProductRepository sku cache is destroyed when cacheLimit is reached ProductRepository sku cache is corrupted when cacheLimit is reached Oct 18, 2017
@heldchen
Copy link
Contributor Author

heldchen commented Oct 18, 2017

Ideally, this pull request should be backported to 2.2, as we were hit pretty hard by this bug during daily product imports for one of our larger 2.2 shop instance.

@orlangur orlangur self-assigned this Oct 18, 2017
@orlangur orlangur added this to the October 2017 milestone Oct 18, 2017
@orlangur orlangur changed the base branch from 2.3-develop to develop October 18, 2017 11:51
@orlangur
Copy link
Contributor

Interesting why 76de251 didn't cover this.

@heldchen thanks for your contribution! Basically 2.2-develop is the new default branch for any contribution, 2.3-develop is not used currently (but it is equal to develop). Maybe it is already documented somewhere of will be documented soon.

@heldchen
Copy link
Contributor Author

heldchen commented Oct 18, 2017

@heldchen thanks for your contribution! Basically 2.2-develop is the new default branch for any contribution, 2.3-develop is not used currently (but it is equal to develop). Maybe it is already documented somewhere of will be documented soon.

ah ok, sorry. should I recreate a new pull request for 2.2-develop or can you move it?

Interesting why 76de251 didn't cover this.

it is not throwing an error but silently returning wrong cache entries if you're "lucky" enough.

in our case, we had >1000 articles loaded with high numeric SKUs (like '123456'). then an article with a low numeric SKU (128) was requested in our import script code. the repository by then had sliced & renumbered the instances array and returned a wrong article with a completely different SKU from the cache instead of loading the real 128 one.

@orlangur
Copy link
Contributor

should I recreate a new pull request for 2.2-develop or can you move it?

Let's just process this one into develop and then you can create another one for 2.2-develop.

it is not throwing an error but silently returning wrong cache entries if you're "lucky" enough.

Yeah, I understand this, just there are two array_slice calls in consecutive lines and only one was fixed while it is obvious that both require array keys preserving.

@magento-team magento-team merged commit f3e91d4 into magento:develop Oct 19, 2017
magento-team pushed a commit that referenced this pull request Oct 19, 2017
@orlangur
Copy link
Contributor

@heldchen thanks for your contribution! You can now do a backport into 2.2-develop.

@heldchen
Copy link
Contributor Author

as I'm not familiar with the magento github workflow and don't want to cause trouble: with backport you mean a cherry pick of 3d6f738 into 2.2-develop, right?

@heldchen heldchen deleted the patch-1 branch October 19, 2017 07:35
@orlangur
Copy link
Contributor

absolutely right.

@heldchen
Copy link
Contributor Author

#11553 - I hope I did everything correctly, if not, I'd appreciate some pointers to avoid the overhead for future PRs. cheers

@tufahu
Copy link
Contributor

tufahu commented Nov 9, 2017

Haha i just wanted to fix it now, we have a shop with all numeric skus ;> thank you @heldchen

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

Successfully merging this pull request may close these issues.

5 participants