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

Random products show out of stock until manual reindex #15984

Closed
AF4Q opened this issue Jun 10, 2018 · 18 comments
Closed

Random products show out of stock until manual reindex #15984

AF4Q opened this issue Jun 10, 2018 · 18 comments
Assignees
Labels
Component: Indexer Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@AF4Q
Copy link

AF4Q commented Jun 10, 2018

I have setup a new Magento store and have been adding products. I have recently noticed that some products are not showing up as out of stock on the front end despite being properly added in the admin panel (i.e. correct inventory, categories etc). Opening and saving these products a few times in the backend fixes this issue. Another way to fix this issue is manually running the reindex command from the SSH. All this time, the crons are properly running and according to the admin panel, the reindex is happening every minute.

Preconditions

  1. Nginx, PHP-FPM, MariaDB, CentOS 7
  2. Magento 2.2.4

Steps to reproduce

  1. Add some products.
  2. Some of the them will show up as out of stock.
  3. Reindex manually and they will show up as in stock.

Expected result

  1. Products should show up in stock without manual reindex.

Actual result

  1. Products only show up in stock after manual reindex.

I have seem two similar issues on StackExchange as well and none of them have gotten a proper answer:
https://magento.stackexchange.com/questions/150656/new-products-not-showing-until-manually-reindexing-although-cron-is-running
https://magento.stackexchange.com/questions/1177/products-seemingly-randomly-disappearing-until-reindex

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jun 10, 2018
@FreekVandeursen
Copy link

We have a problem in our shop which might be the same issue. Once in a while products seem to disappear from the cataloginventory_stock_status table.
I have set up monitoring to check whether all enabled products have a corresponding entry in that index table. This is usually the case, but sometimes I get alerts that a number of products have disappeared from that table. And it doesn't seem to be temporary. The products only reappear in that table after a manual reindex.

So far I haven't been able to find out what circumstances will trigger this disappearing of products, although I have an unconfirmed suspicion that it has something to do with large number of products being reindex via the mview scheduled indexer.

@ghost ghost self-assigned this Jul 6, 2018
@ghost ghost added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Jul 6, 2018
@ghost
Copy link

ghost commented Jul 6, 2018

Hi @AF4Q I cannot reproduce by your scenarious steps in clean magento , can you provide more information ?

@ghost ghost added Progress: needs update Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release and removed Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Progress: needs update labels Jul 6, 2018
@ghost
Copy link

ghost commented Jul 6, 2018

I resolved the problem, you need to set settings for indexer on save action System->Index manager chose checkbox stock -> set to -> update on save. In my case that work

@ghost
Copy link

ghost commented Jul 6, 2018

@AF4Q seems like duplicate to this -> #15939

@erikhansen
Copy link
Contributor

@engcom-backlog-nazar While changing the index to "UPDATE ON SAVE" may work around the issue, Magento actually recommends using the "UPDATE BY SCHEDULE" option for production environments. Here's a quote from a Magento Support ticket where I asked for Magento's official stance on this:

When in production we always recommend UPDATE BY SCHEDULED, when in development then UPDATE ON SAVE. UPDATE BY SCHEDULE uses the crontab to run magento cron jobs which causes the indexers to run more efficiently while the store is open. So, always UPDATE BY SCHEDULE when in production but remember that means the cron tab needs to be set to run the Magento cron jobs.

@AF4Q Is your "Stock" index set to "UPDATE ON SAVE" or "UPDATE BY SCHEDULE" when you're experiencing this?

@ghost
Copy link

ghost commented Jul 9, 2018

HI @AF4Q I checked this, the indexer oh state "UPDATE BY SCHEDULE" must be update partial and product may be changed. thank you for you report We've acknowledged the issue and added to our backlog.

@ghost ghost added Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Jul 9, 2018
@ghost ghost removed their assignment Jul 9, 2018
@AF4Q
Copy link
Author

AF4Q commented Jul 9, 2018

My indexer is set to UPDATE BY SCHEDULE and in the admin panel it shows that all indexes are valid. But still this issue persists. Upon running a manual index by SSH fixes the issue.

@Tereta
Copy link

Tereta commented Aug 9, 2018

code/vendor/magento/module-catalog-inventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php : _updateIndex
$this->deleteOldRecords($entityIds) should be before $this->_updateIndexTable($data) where update by bunch and select "while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {"

The magento developers forget about bunch update by 1000 thus it's insert update to table and after it clean the data in the cataloginventory_stock_status

@matthew-muscat
Copy link
Contributor

Closing this issue — a fix for this has been applied and is available in v2.2.5

The fix for this can be located in #12205

@matthew-muscat
Copy link
Contributor

Actually.. sorry, re-opening..

@engcom-backlog-nazar — is this something we could backport to affected versions?

@ghost
Copy link

ghost commented Sep 6, 2018

@matthew-muscat Close this is as duplicate to #15939

@ghost ghost closed this as completed Sep 6, 2018
@jmukhtar
Copy link

Hi, I am running Magento v2.2.5 but i am still experiencing the exact same issue that the product doesn't appear under the category until manual re-index is run.

Whereas it appears straight away in the search (we are using klevu).

Can anyone pass a reference form the Magento docs that refer this issue being included. I can't find it in any of the Magento release notes.

@Clud7
Copy link

Clud7 commented Jul 4, 2019

code/vendor/magento/module-catalog-inventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php : _updateIndex
$this->deleteOldRecords($entityIds) should be before $this->_updateIndexTable($data) where update by bunch and select "while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {"

The magento developers forget about bunch update by 1000 thus it's insert update to table and after it clean the data in the cataloginventory_stock_status

I need help on this! Magento 2.3.1 here. After SKU 1000 skus magento updates the stock only for the next skus ignoring the first 1000. On 1160 sku i have salable quantity stock only for the last 160.

@ghost
Copy link

ghost commented Oct 18, 2019

Still an in issue in 2.3.3, this issue alone has at this point cost my client tens of thousands of dollars.
Update on save DOES NOT work.
Writing your own indexer to control the stock indexer that fixes all of it DOES NOT work.
Magento2 is bugridden garbage, it takes 4x as long to achieve anything in it than our last store and bugs are constant and hard to fix.

Attempting to rip out the indexer itself at this point. Never will I suggest m2 to anyone, it's been 3 years of hell.

@domeglic
Copy link

As @Clud7 explained, this problem occurs when at least 1000 products of the same type are being reindex.
This problem will not be visible unless you have enough products. Here is an easy way to reproduce:

  • Set cataloginventory_stock index to mode scheduled
  • Simulate products getting changed:
    INSERT INTO cataloginventory_stock_cl(entity_id) SELECT a.entity_id FROM catalog_product_entity a INNER JOIN cataloginventory_stock_status b ON a.entity_id=b.product_id AND b.website_id=0 WHERE a.type_id='simple'
  • Run cron:run and wait until index turns green index:status

Now go to Gear->Bags for example and see no products. Stock index contains only around 1000 products instead of 2000.

The problem is here, when 1000 products are processed they are updated and at the end of the loop all products are deleted.

@hostep
Copy link
Contributor

hostep commented Oct 24, 2019

Let's reopen this one based on the last comments and on #12205 (comment), maybe somebody from Magento can try to reproduce this.

Would it be enough to forward port 20d7afb to 2.3-develop?

@hostep hostep reopened this Oct 24, 2019
@ghost ghost removed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Oct 24, 2019
@ghost ghost assigned hostep Oct 27, 2019
@hostep
Copy link
Contributor

hostep commented Oct 27, 2019

@domeglic: thanks for listing those steps to reproduce, that was really helpful!

I was able to reproduce this problem and forward ported 20d7afb in this new PR to 2.3-develop.
This seems to fix the problem!

@VladimirZaets
Copy link
Contributor

Hi @AF4Q. Thank you for your report.
The issue has been fixed in #25306 by @hostep in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.5 release.

@VladimirZaets VladimirZaets added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Indexer Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests