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
Write a patchWrite change recordsReview and feedbackRTBC and feedbackCommitRelease- released in 8.0.0-alpha3
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 3187670-15-backend-down-MR63.diff | 6.94 KB | isampo |
| #13 | after-patch.png | 102.26 KB | man-1982 |
| #13 | before-patch.png | 124.67 KB | man-1982 |
| #4 | 3187670-catch-error-on-backend-down-4.patch | 759 bytes | sokru |
Issue fork elasticsearch_connector-3187670
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
sokru commentedComment #3
drunken monkeyThis is a bug in the Elasticsearch Connector module, not in the Search API. Per the interface,
\Drupal\search_api\Backend\BackendSpecificInterface::search()is only allowed to throwSearchApiException. Other exceptions have to be caught by the backend plugin and re-wrapped.Comment #4
sokru commentedThanks @drunken monkey for the feedback.
Patch should catch when Elasticsearch backend is not available.
Comment #5
sokru commentedComment #6
bburg+1, this module needs better error handling when the server isn't available.
Comment #7
mparker17I 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.
Comment #8
it-cru@sokru: Maybe it make sense to fix it first in 8.0.x-dev and than backport solution to 8.x-7.x-dev?
Comment #9
sokru commentedActually still applies to 8.0.x-dev (and search_api_opensearch).
Comment #10
sokru commentedThe 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...
Comment #12
sokru commentedAdded the tests, reverting the changes to
src/SearchAPI/BackendClient.phpwill 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.
Comment #13
man-1982 commentedReport:

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
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
Comment #14
man-1982 commentedComment #15
isampo commentedMR63 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.
Comment #17
sokru commentedCommitted to 8.0.x, not sure if I find a time to fix this also on 8.x-7.x.
Comment #19
mparker17Note this was released in elasticsearch_connector-8.0.0-alpha3.
Comment #20
mparker17Updated issue summary to mention when it was released as well.