entity.search_api_index.canonical route will produce fatal error when backend is down

Created on 10 December 2020, about 4 years ago
Updated 20 September 2024, 3 months ago

Problem/Motivation

If search backend is unreachable, several Search API routes will throw fatal error. Affected routes are at least entity.search_api_index.canonical, entity.search_api_server.canonical search_api.overview. This is because Elasticsearch Connector BackendClient assumes the Elasticsearch backend is up-and-running.

Steps to reproduce

1. Create server and index.
2. Shut down search backend, e.g. sudo service elasticsearch stop or change the connector url port to some non-existing eg: $config['search_api.server.elasticsearch_server']['backend_config']['connector_config']['url'] = "http://drupal-elasticsearch.ddev.site:9999"
3. Go to /admin/config/search/search-api/index/{index_name}

Fatal error is produced.

The website encountered an unexpected error. Please try again later.

Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes found in your cluster in Elasticsearch\ConnectionPool\StaticNoPingConnectionPool->nextConnection() (line 64 of /var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ConnectionPool/StaticNoPingConnectionPool.php).
Elasticsearch\Transport->getConnection() (Line: 99)
Elasticsearch\Transport->performRequest('HEAD', '/my_test_index', Array, NULL, Array) (Line: 292)
Elasticsearch\Connections\Connection->Elasticsearch\Connections\{closure}(Array) (Line: 28)
React\Promise\FulfilledPromise->then(Object, NULL, NULL) (Line: 55)
GuzzleHttp\Ring\Future\CompletedFutureValue->then(Object, NULL, NULL) (Line: 341)
GuzzleHttp\Ring\Core::proxy(Object, Object) (Line: 340)
Elasticsearch\Connections\Connection->Elasticsearch\Connections\{closure}(Array, Object, Object, Array) (Line: 236)
Elasticsearch\Connections\Connection->performRequest('HEAD', '/my_test_index', Array, NULL, Array, Object) (Line: 110)
Elasticsearch\Transport->performRequest('HEAD', '/my_test_index', Array, NULL, Array) (Line: 43)
Elasticsearch\Namespaces\BooleanRequestWrapper::performRequest(Object, Object) (Line: 292)
Elasticsearch\Namespaces\IndicesNamespace->exists(Array) (Line: 615)
Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend->search(Object) (Line: 468)
Drupal\search_api\Entity\Server->search(Object) (Line: 539)
Drupal\search_api\Query\Query->execute() (Line: 311)
template_preprocess_search_api_index(Array, 'search_api_index', Array) (Line: 305)

Proposed resolution

Use try/catch method when connecting the backend.

Remaining tasks

🐛 Bug report
Status

Fixed

Version

8.0

Component

Code

Created by

🇫🇮Finland sokru

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇦Canada mparker17 UTC-4

    I think when this issue was moved into the elasticsearch_connector queue, its version number wasn't updated, because the patch applies to 8.x-7.x. Updating the version.

  • 🇩🇪Germany IT-Cru Munich

    @sokru: Maybe it make sense to fix it first in 8.0.x-dev and than backport solution to 8.x-7.x-dev?

  • Status changed to Needs work 4 months ago
  • 🇫🇮Finland sokru

    Actually still applies to 8.0.x-dev (and search_api_opensearch).

  • 🇫🇮Finland sokru

    The MR handles the error, but wonder if this needs a Functional test, something like https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/tests/src/F...

  • Merge request !63Issue 3187670: Catch no nodes alive exception → (Merged) created by sokru
  • Status changed to Needs review 4 months ago
  • 🇫🇮Finland sokru

    Added the tests, reverting the changes to src/SearchAPI/BackendClient.php will make the test fail.

    I added one @todo comment with link to upstream issue (https://github.com/elastic/elasticsearch-php/issues/1308) getting that done would help providing more informative error messages. Currently the wrong port will produce an error "Elastic\Transport\Exception\NoNodeAvailableException: No alive nodes. All the 1 nodes seem to be down", which is misleading.

    The title of this issue could be better.

  • Status changed to RTBC 3 months ago
  • 🇨🇦Canada man-1982

    Report:
    1. I added bad Elasticsearch conf, which doesn work on my local env
    2. I had this error

    3. Applied patch through composer in composer patches part

    "drupal/elasticsearch_connector": {
                    "produce fatal error when backend is down": "https://git.drupalcode.org/project/elasticsearch_connector/-/merge_requests/63.patch"
                }

    4. Patch was applied without problem, all passed smoothly
    5. as a result a can see list of my servers and index

    I strongly recommend apply this changes to module.
    It seems to me, there is a critical issue, because we don't have access to servers search list without this patch

    thanks to
    @kallevu
    @sokru

  • 🇫🇮Finland iSampo

    MR63 working as it should, the error is no longer appearing with faulty URLs. Attached is a patch from the current MR63 changes to get a static patch for composer installs.

  • Pipeline finished with Skipped
    3 months ago
    #287901
    • sokru committed 5ccc2982 on 8.0.x
      Issue #3187670 by sokru, man-1982: entity.search_api_index.canonical...
  • Status changed to Fixed 3 months ago
  • 🇫🇮Finland sokru

    Committed to 8.0.x, not sure if I find a time to fix this also on 8.x-7.x.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024