Skip to content

Elasticsearch timeout not working if elasticsearch got stuck #38289

Open
@p24-max

Description

@p24-max

We had a scenario where the elastic search server had 100% memory utilization. This caused a downtime of the entire shop, even if the elasticsearch is not required for product-detail page, cart, checkout.
Root cause was, that all the php-fpm workers were blocked because elasticsearch requests were not timed out.

Preconditions and environment

  • Magento version 2.4.6-p3
  • Incredibly slow / stuck elasticsearch (e.g. due to 100% server memory utilization)

Steps to reproduce

  • It might not be reproducible with @magento provided dev instance
  • With docker, you can pause the elasticsearch docker container. It is not reproducible when docker container is stopped!

Expected result

Configured elasticsearch timeout kicks in and cancels the request

Actual result

Request is executed until php max_execution_time is exceeded

Additional information

I developed a hotfix-patch for this, which can be used as base for a final solution. With this, it works as expected:

===================================================================
diff --git a/vendor/magento/module-elasticsearch-7/SearchAdapter/Mapper.php b/vendor/magento/module-elasticsearch-7/SearchAdapter/Mapper.php
--- a/vendor/magento/module-elasticsearch-7/SearchAdapter/Mapper.php
+++ b/vendor/magento/module-elasticsearch-7/SearchAdapter/Mapper.php	(date 1702503910793)
@@ -39,6 +39,8 @@
     {
         $searchQuery = $this->mapper->buildQuery($request);
         $searchQuery['track_total_hits'] = true;
+        $searchQuery['client']['timeout'] = 2;
+        $searchQuery['client']['connect_timeout'] = 0.5;
         return $searchQuery;
     }
 }

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: ElasticsearchIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: ready for devReported on 2.4.6-p3Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions