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

Created on 10 December 2020, almost 4 years ago
Updated 20 September 2024, about 2 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.

Production build 0.71.5 2024