Skip to content

Commit 2860bca

Browse files
committed
[FIXUP] Use dbQueryTimeout in CH driver
1 parent 98287d6 commit 2860bca

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/cubejs-backend-shared/src/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ const variables: Record<string, (...args: any) => any> = {
532532
},
533533

534534
/**
535-
* Query timeout. Currently used in BigQuery, Dremio, Postgres, Snowflake
535+
* Query timeout. Currently used in BigQuery, ClickHouse, Dremio, Postgres, Snowflake
536536
* and Athena drivers and the orchestrator (queues, pre-aggs). For the
537537
* orchestrator this variable did not split by the datasource.
538538
*

packages/cubejs-clickhouse-driver/src/ClickHouseDriver.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export interface ClickHouseDriverOptions {
6666
protocol?: string,
6767
database?: string,
6868
readOnly?: boolean,
69+
/**
70+
* Timeout in milliseconds for requests to ClickHouse.
71+
* Default is 10 minutes
72+
*/
73+
requestTimeout?: number,
6974

7075
/**
7176
* Data source name.
@@ -104,6 +109,7 @@ type ClickHouseDriverConfig = {
104109
password: string,
105110
readOnly: boolean,
106111
database: string,
112+
requestTimeout: number,
107113
exportBucket: ClickhouseDriverExportAWS | null,
108114
clickhouseSettings: ClickHouseSettings,
109115
};
@@ -149,13 +155,18 @@ export class ClickHouseDriver extends BaseDriver implements DriverInterface {
149155
this.readOnlyMode =
150156
getEnv('clickhouseReadOnly', { dataSource }) === 'true';
151157

158+
// Expect that getEnv('dbQueryTimeout') will always return a value
159+
const requestTimeoutEnv: number = getEnv('dbQueryTimeout', { dataSource }) * 1000;
160+
const requestTimeout = config.requestTimeout ?? requestTimeoutEnv;
161+
152162
this.config = {
153163
url,
154164
username,
155165
password,
156166
database,
157167
exportBucket: this.getExportBucket(dataSource),
158168
readOnly: !!config.readOnly,
169+
requestTimeout,
159170
clickhouseSettings: {
160171
// If ClickHouse user's permissions are restricted with "readonly = 1",
161172
// change settings queries are not allowed. Thus, "join_use_nulls" setting
@@ -208,6 +219,7 @@ export class ClickHouseDriver extends BaseDriver implements DriverInterface {
208219
password: this.config.password,
209220
database: this.config.database,
210221
clickhouse_settings: this.config.clickhouseSettings,
222+
request_timeout: this.config.requestTimeout,
211223
max_open_connections: maxPoolSize,
212224
});
213225
}

0 commit comments

Comments
 (0)