From 71ba8f303749627d247e45ff33be409f98ce2aa0 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Wed, 18 Oct 2023 11:32:29 +0300 Subject: [PATCH] [ES|QL] Force ES client timeout after 2 minutes (#168929) ## Summary We found out that for ES|QL queries while the kibana server (and browser) timeouts in 2 minutes, the requests are still running in ES. So instead of being aborted in 2 minutes, the hit a 5minute timeout from the proxy which retries 3 times and then aborts. This happens ONLY when bfetch is enabled (which is the default) After an investigation with Rudolf it seems that we don't abort correctly in bsearch. Lukas is fixing it here https://github.com/elastic/kibana/pull/169041 . (cherry picked from commit 6037805fb068c8dc703999f656b110e986279614) --- .../esql_search/esql_search_strategy.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/server/search/strategies/esql_search/esql_search_strategy.ts b/src/plugins/data/server/search/strategies/esql_search/esql_search_strategy.ts index 7f3f6f521853d4..2af032826189fb 100644 --- a/src/plugins/data/server/search/strategies/esql_search/esql_search_strategy.ts +++ b/src/plugins/data/server/search/strategies/esql_search/esql_search_strategy.ts @@ -11,6 +11,8 @@ import type { Logger } from '@kbn/core/server'; import { getKbnServerError, KbnServerError } from '@kbn/kibana-utils-plugin/server'; import type { ISearchStrategy } from '../../types'; +const ES_TIMEOUT_IN_MS = 120000; + export const esqlSearchStrategyProvider = ( logger: Logger, useInternalUser: boolean = false @@ -23,6 +25,17 @@ export const esqlSearchStrategyProvider = ( * @returns `Observable>` */ search: (request, { abortSignal, ...options }, { esClient, uiSettingsClient }) => { + const abortController = new AbortController(); + // We found out that there are cases where we are not aborting correctly + // For this reasons we want to manually cancel he abort signal after 2 mins + + abortSignal?.addEventListener('abort', () => { + abortController.abort(); + }); + + // Also abort after two mins + setTimeout(() => abortController.abort(), ES_TIMEOUT_IN_MS); + // Only default index pattern type is supported here. // See ese for other type support. if (request.indexType) { @@ -41,8 +54,10 @@ export const esqlSearchStrategyProvider = ( }, }, { - signal: abortSignal, + signal: abortController.signal, meta: true, + // we don't want the ES client to retry (default value is 3) + maxRetries: 0, } ); return {