@@ -7,6 +7,9 @@ import { singleton } from "~/utils/singleton";
77import type { OrganizationDataStoresRegistry } from "~/services/dataStores/organizationDataStoresRegistry.server" ;
88import { type IEventRepository } from "~/v3/eventRepository/eventRepository.types" ;
99
10+ // Declared before the singletons below, which initialize clients at module load.
11+ const LOGS_LIST_REQUEST_TIMEOUT_MARGIN_SECONDS = 5 ;
12+
1013// ---------------------------------------------------------------------------
1114// Default clients (singleton per process)
1215// ---------------------------------------------------------------------------
@@ -70,15 +73,23 @@ function getLogsListClickhouseSettings() {
7073 filesystem_cache_prefer_bigger_buffer_size :
7174 env . CLICKHOUSE_LOGS_LIST_FILESYSTEM_CACHE_PREFER_BIGGER_BUFFER_SIZE ,
7275 } ) ,
73- ... ( env . CLICKHOUSE_LOGS_LIST_MAX_ROWS_TO_READ && {
74- max_rows_to_read : env . CLICKHOUSE_LOGS_LIST_MAX_ROWS_TO_READ . toString ( ) ,
75- } ) ,
76+ // No max_rows_to_read: ClickHouse checks it against the estimated rows of every selected
77+ // granule before reading, which rejects newest-first LIMIT queries on large environments that
78+ // would stop after a few thousand rows. max_execution_time bounds the work instead.
7679 ...( env . CLICKHOUSE_LOGS_LIST_MAX_EXECUTION_TIME && {
7780 max_execution_time : env . CLICKHOUSE_LOGS_LIST_MAX_EXECUTION_TIME ,
7881 } ) ,
7982 } ;
8083}
8184
85+ /** Outlasts the server-side limit so ClickHouse cancels the query and reports why. */
86+ function getLogsListRequestTimeoutMs ( ) {
87+ if ( ! env . CLICKHOUSE_LOGS_LIST_MAX_EXECUTION_TIME ) return undefined ;
88+ return (
89+ ( env . CLICKHOUSE_LOGS_LIST_MAX_EXECUTION_TIME + LOGS_LIST_REQUEST_TIMEOUT_MARGIN_SECONDS ) * 1000
90+ ) ;
91+ }
92+
8293function initializeLogsClickhouseClient ( ) {
8394 const url = new URL (
8495 env . LOGS_SEARCH_READER_CLICKHOUSE_URL ?? env . CLICKHOUSE_READER_URL ?? env . CLICKHOUSE_URL
@@ -95,6 +106,7 @@ function initializeLogsClickhouseClient() {
95106 logLevel : env . CLICKHOUSE_LOG_LEVEL ,
96107 compression : { request : true } ,
97108 maxOpenConnections : env . CLICKHOUSE_MAX_OPEN_CONNECTIONS ,
109+ requestTimeoutMs : getLogsListRequestTimeoutMs ( ) ,
98110 clickhouseSettings : getLogsListClickhouseSettings ( ) ,
99111 } ) ;
100112}
@@ -592,6 +604,7 @@ function buildOrgClickhouseClient(url: string, clientType: ClientType): ClickHou
592604 logLevel : env . CLICKHOUSE_LOG_LEVEL ,
593605 compression : { request : true } ,
594606 maxOpenConnections : env . CLICKHOUSE_MAX_OPEN_CONNECTIONS ,
607+ requestTimeoutMs : getLogsListRequestTimeoutMs ( ) ,
595608 clickhouseSettings : getLogsListClickhouseSettings ( ) ,
596609 } ) ;
597610 case "engine" :
0 commit comments