Opensearch clients do not apply server_timeout to search queries
Preconditions and environment
- Magento 2.4.7-p10 (also reproduces on current 2.4-develop; affected code is unchanged)
- PHP 8.3
- Catalog Search engine set to
opensearch - Library versions:
opensearch-project/opensearch-php2.x,ezimuel/ringphp^1.4
Steps to reproduce
- Configure Catalog Search with the
opensearchengine and set Stores > Configuration > Catalog > Catalog Search > OpenSearch Server Timeout to a low value, for example5. - Cause the search backend to accept a TCP connection but never return a response body. This can be simulated by pointing the engine at a socket that black-holes after connect, or by inducing a transient network partition to the search host while a query is in flight so the peer's FIN/RST is lost and the client is left with a half-open connection.
- Issue a storefront search (or any request that triggers
\Magento\OpenSearch\Model\SearchClient::query()).
Expected result
- The search request is bounded by the configured OpenSearch Server Timeout (
server_timeout, default 15s) and fails after that period, freeing the worker. - A misbehaving or unreachable search backend cannot block a request indefinitely.
Actual result
- The configured
server_timeoutis not applied to search queries. It is only applied toping()/ Test Connection. - Search queries fall back to the transport default, which has no overall/read timeout (
CURLOPT_TIMEOUTunset = 0 = infinite). The request blocks forever, holding the PHP-FPM worker. Enough such requests exhaustpm.max_children, saturating the pool: new connections queue unaccepted (observedRecv-Qin the hundreds on the FPM listener) and the instance stops serving HTTP even though the search cluster itself has recovered.
Additional information
The configured timeout is read correctly but is only wired to ping(), and the value is silently discarded when the client is built. Validated against magento/[email protected], app/code/Magento/OpenSearch/Model/SearchClient.php.
1. The option is populated (default 15s) — Magento\Elasticsearch\Model\Config::prepareClientOptions() (shared config provider used by the OpenSearch engine):
// app/code/Magento/Elasticsearch/Model/Config.php
'timeout' => $this->getElasticsearchConfigData('server_timeout') ?: self::ELASTICSEARCH_DEFAULT_TIMEOUT, // 152. Only ping() uses it; query() does not — Magento\OpenSearch\Model\SearchClient:
// ping() (L104-111): timeout applied
public function ping(): bool
{
if ($this->pingResult === null) {
$this->pingResult = $this->getOpenSearchClient()
->ping(['client' => ['timeout' => $this->clientOptions['timeout']]]);
}
return $this->pingResult;
}
// query() (L294-297): no 'client' => ['timeout' => ...] passed
public function query(array $query): array
{
return $this->getOpenSearchClient()->search($query);
}bulkQuery() (L152-156) and the other data methods likewise pass no timeout.
3. The timeout option is dropped when building the client. getOpenSearchClient() (L97-100) builds the client via ClientBuilder::fromConfig($config, true), where $config comes from buildOSConfig(). buildOSConfig() adds only the hosts key and passes timeout through unchanged; it sets no connectionParams, connect_timeout, or per-request client key, and calls no setTimeout. fromConfig then maps a config key only if a matching setter exists; otherwise, because $quiet = true, it discards the key without error. There is no setTimeout() on ClientBuilder, and timeout is not whitelisted:
// vendor/opensearch-project/opensearch-php/src/OpenSearch/ClientBuilder.php
public const ALLOWED_METHODS_FROM_CONFIG = ['includePortInHostHeader']; // 'timeout' absent
...
$method = in_array($key, self::ALLOWED_METHODS_FROM_CONFIG, true) ? $key : "set$key"; // 'timeout' -> settimeout() (does not exist) -> droppedSo the timeout is placed in the config, threaded through buildOSConfig(), then silently dropped at fromConfig(..., true). No data method re-supplies it per request.
4. The transport has no read timeout. opensearch-project/opensearch-php depends on ezimuel/ringphp, and Magento builds the legacy (RingPHP) client. With nothing passed on the query, requests use RingPHP defaults:
// vendor/ezimuel/ringphp/src/Client/CurlFactory.php
CURLOPT_CONNECTTIMEOUT => 150, // connect only
// CURLOPT_TIMEOUT is set only if the caller supplies a 'timeout'; otherwise unset (curl default 0 = infinite)Suggested fix
Apply the configured timeout to data requests, not just ping(). For example, pass the per-request client option in each data method of OpenSearch\Model\SearchClient:
public function query(array $query): array
{
$query['client']['timeout'] = $this->clientOptions['timeout'];
return $this->getOpenSearchClient()->search($query);
}Alternatively, set a default request timeout at client-build time so all requests inherit server_timeout. A separate, explicit connect timeout would also be desirable (currently fixed at RingPHP's 150s). At minimum, the documentation for OpenSearch Server Timeout should state that it currently governs only connection testing, not query execution.
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”.
Source: magento/magento2