Skip to content

Handle exceptions thrown in child processes forked by ProcessManager #30626

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

Conversation

pawel-siejba
Copy link
Contributor

Description (*)

The following bug can have fatal consequences if somebody employed any form of exception handling around indexers in their installation, as it could lead to very hard to discover bugs, that appear only on environments with several threads available, and MAGE_INDEXER_THREADS_COUNT env variable set.

As of now in Vanilla Magento 3 indexers(catalogsearch_fulltext, catalog_category_product, catalog_product_price) use the process manager for splitting index dimensions into separate processes.

If one of the subprocesses fails, it's not exited immediately, instead the exception continues through parent's execution flow

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Process Manager doesn't handle exceptions properly in forked processes #30622

Manual testing scenarios (*)

  1. Run MAGE_INDEXER_THREADS_COUNT=4 php bin/magento indexer:reindex catalogsearch_fulltext
  2. Kill Elasticsearch process to simulate an exception thrown or hard code an exception in the callables passed to ProcessManager

Questions or comments

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 are green)

@m2-assistant
Copy link

m2-assistant bot commented Oct 23, 2020

Hi @pawel-siejba. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@magento-engcom-team magento-engcom-team added Component: Indexer Release Line: 2.4 Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner Event: MageCONF CD 2020 labels Oct 23, 2020
@ihor-sviziev ihor-sviziev self-assigned this Oct 23, 2020
@ihor-sviziev
Copy link
Contributor

@magento run all tests

@pawel-siejba
Copy link
Contributor Author

Can be easily back ported all the way to 2.3.0 Without any changes up to 2.3.2, 2.3.0 - 2.3.1 have some phpcs comments removed, but the class stays intact.

@ihor-sviziev
Copy link
Contributor

@pawel-siejba
Your changes looks good. Let's wait for test results.
Will you be able to cover your change with any type of automated tests?

@ihor-sviziev ihor-sviziev added Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests Award: bug fix Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Progress: review labels Oct 23, 2020
@pawel-siejba pawel-siejba force-pushed the issue-30662-process-manager-forked-processes-exit-as-parent branch from 86bede4 to bdf911a Compare October 23, 2020 16:04
@pawel-siejba
Copy link
Contributor Author

@magento run Static Tests

@pawel-siejba
Copy link
Contributor Author

@ihor-sviziev I'll try to write some Unit Tests but I'm not sure if PHPUnit will handle that well as we will be essentially testing process forking.

@pawel-siejba
Copy link
Contributor Author

@magento run all tests

@pawel-siejba
Copy link
Contributor Author

@magento run Functional Tests CE, Functional Tests EE, Functional Tests B2B

@pawel-siejba
Copy link
Contributor Author

@ihor-sviziev It doesn't look like writing Unit tests in this case will be feasible. Additional extensions installed may be required, on top of that it looks to be impossible to Unit test this implementation of Process manager in a way that would prove useful to this PR - without mocking/replacing the pcntl extension function calls. Moreover forking inside a Unit test doesn't seem like the best idea to me.

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-8375 has been created to process this Pull Request

@sidolov sidolov added the Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. label Oct 27, 2020
@engcom-Delta engcom-Delta self-assigned this Oct 29, 2020
Copy link
Contributor

@engcom-Delta engcom-Delta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pawel-siejba with new changes we have same output as before but it is recorded into exception.log file. Could you clarify if this is expected behavior with your fix?
Manual testing scenario:

  • Create additional website with products
    image
  • Run MAGE_INDEXER_THREADS_COUNT=4 php bin/magento indexer:reindex catalogsearch_fulltext
  • Kill Elasticsearch process to simulate an exception thrown (e.g., kill pid command)

Output on 2.4-develop:
Screenshot from 2020-11-17 21-40-26

Output with fix in console:
image
Output with fix in log file:
exception.log

@pawel-siejba
Copy link
Contributor Author

pawel-siejba commented Nov 18, 2020

@engcom-Delta Yes, this is the expected behaviour. BTW don't know if you noticed but you unveiled another bug with the ProcessManager that I will create a separate issue for as it's not related to this change and also reproducible without this change. Basically if MAGE_INDEXER_THREADS_COUNT > Number of dimensions(in your case 3 stores) the main process always exits successfully.

#30964

@engcom-Delta
Copy link
Contributor

@pawel-siejba thanks for clarification
@ihor-sviziev Could you approve to move PR into ready for testing column?

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-8375 has been created to process this Pull Request

@engcom-Delta
Copy link
Contributor

✔️ QA passed
Was checked case from Manual testing scenarios
Before:
❌ Errors are shown in the console
image

After:
✔️ Errors are recorded into log file
image
exception.log:

[2020-11-19 16:24:48] main.ERROR: Child process failed with message: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for this URL.</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at localhost Port 80</address>
</body></html>
 {"exception":"[object] (Elasticsearch\\Common\\Exceptions\\BadRequest400Exception(code: 405): <!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for this URL.</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at localhost Port 80</address>
</body></html>
 at /var/www/html/magento2dev/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:632)"} []
[2020-11-19 16:24:48] main.ERROR: Child process failed with message: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for this URL.</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at localhost Port 80</address>
</body></html>
 {"exception":"[object] (Elasticsearch\\Common\\Exceptions\\BadRequest400Exception(code: 405): <!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for this URL.</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at localhost Port 80</address>
</body></html>
 at /var/www/html/magento2dev/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:632)"} []

Note: Issue with the main process always exits successfully is reproducible on 2.4-develop without fix:
#30626 (comment)

@engcom-Delta engcom-Delta added QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope and removed QA: Ready to add to Regression Scope Should be analyzed and added to Regression Testing Scope(if applicable) labels Nov 19, 2020
@engcom-Delta
Copy link
Contributor

Note: Automation tests are passed

@m2-assistant
Copy link

m2-assistant bot commented Dec 10, 2020

Hi @pawel-siejba, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests Award: bug fix Component: Indexer Event: MageCONF CD 2020 Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S0 A problem that is blocking the ability to work. An immediate fix is needed. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Process Manager doesn't handle exceptions properly in forked processes
7 participants