Skip to content

Commit f91e999

Browse files
feat: wrapper connect and query timeouts (#342)
1 parent e58e8e9 commit f91e999

10 files changed

Lines changed: 95 additions & 22 deletions

File tree

common/lib/driver_dialect/driver_dialect.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@ export interface DriverDialect {
2828

2929
getAwsPoolClient(props: any): AwsPoolClient;
3030

31+
setConnectTimeout(props: Map<string, any>, wrapperConnectTimeout?: any): void;
32+
33+
setQueryTimeout(props: Map<string, any>, sql?: any, wrapperConnectTimeout?: any): void;
34+
3135
setKeepAliveProperties(props: Map<string, any>, keepAliveProps: any): void;
3236
}

common/lib/mysql_client_wrapper.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ import { ClientWrapper } from "./client_wrapper";
1818
import { HostInfo } from "./host_info";
1919
import { ClientUtils } from "./utils/client_utils";
2020
import { uniqueId } from "../logutils";
21+
import { DriverDialect } from "./driver_dialect/driver_dialect";
2122

2223
/*
2324
This is an internal wrapper class for the target community driver client created by the MySQL2DriverDialect.
2425
*/
2526
export class MySQLClientWrapper implements ClientWrapper {
27+
private readonly driverDialect: DriverDialect;
2628
readonly client: any;
2729
readonly hostInfo: HostInfo;
2830
readonly properties: Map<string, string>;
@@ -34,15 +36,18 @@ export class MySQLClientWrapper implements ClientWrapper {
3436
* @param targetClient The community driver client created for an instance.
3537
* @param hostInfo Host information for the connected instance.
3638
* @param properties Connection properties for the target client.
39+
* @param driverDialect The driver dialect to obtain driver-specific information.
3740
*/
38-
constructor(targetClient: any, hostInfo: HostInfo, properties: Map<string, any>) {
41+
constructor(targetClient: any, hostInfo: HostInfo, properties: Map<string, any>, driverDialect: DriverDialect) {
3942
this.client = targetClient;
4043
this.hostInfo = hostInfo;
4144
this.properties = properties;
45+
this.driverDialect = driverDialect;
4246
this.id = uniqueId("MySQLClient_");
4347
}
4448

4549
query(sql: any): Promise<any> {
50+
this.driverDialect.setQueryTimeout(this.properties, sql);
4651
return this.client?.query(sql);
4752
}
4853

common/lib/utils/client_utils.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,26 @@ import { getTimeoutTask } from "./utils";
1818
import { Messages } from "./messages";
1919
import { AwsWrapperError, InternalQueryTimeoutError } from "./errors";
2020
import { WrapperProperties } from "../wrapper_property";
21+
import { logger } from "../../logutils";
2122

2223
export class ClientUtils {
24+
static hasWarnedDeprecation: boolean = false;
2325
static async queryWithTimeout(newPromise: Promise<any>, props: Map<string, any>, timeValue?: number): Promise<any> {
2426
const timer: any = {};
25-
const timeoutTask = getTimeoutTask(
26-
timer,
27-
Messages.get("ClientUtils.queryTaskTimeout"),
28-
timeValue ?? WrapperProperties.INTERNAL_QUERY_TIMEOUT.get(props)
29-
);
27+
let timeout = timeValue;
28+
if (props.has(WrapperProperties.INTERNAL_QUERY_TIMEOUT.name)) {
29+
timeout = WrapperProperties.INTERNAL_QUERY_TIMEOUT.get(props);
30+
if (!ClientUtils.hasWarnedDeprecation) {
31+
logger.warn(
32+
"The connection configuration property 'mysqlQueryTimeout' is deprecated since version 1.1.0. Please use 'wrapperQueryTimeout' instead."
33+
);
34+
ClientUtils.hasWarnedDeprecation = true;
35+
}
36+
}
37+
if (!timeout) {
38+
timeout = WrapperProperties.WRAPPER_QUERY_TIMEOUT.get(props);
39+
}
40+
const timeoutTask = getTimeoutTask(timer, Messages.get("ClientUtils.queryTaskTimeout"), timeout);
3041
return await Promise.race([timeoutTask, newPromise])
3142
.catch((error: any) => {
3243
if (error instanceof InternalQueryTimeoutError) {

common/lib/utils/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"ConnectionProvider.unsupportedHostSelectorStrategy": "Unsupported host selection strategy '%s' specified for this connection provider '%s'. Please visit the documentation for all supported strategies.",
66
"ConnectionPluginChainBuilder.errorImportingPlugin": "The plugin could not be imported due to error '%s'. Please ensure the required dependencies have been installed. Plugin: '%s'",
77
"ClientUtils.queryTaskTimeout": "Client query task timed out, if a network error did not occur, please review the usage of the 'mysqlQueryTimeout' connection parameter.",
8+
"ClientUtils.connectTimeout": "Client connect timed out.",
89
"DialectManager.unknownDialectCode": "Unknown dialect code: '%s'.",
910
"DialectManager.getDialectError": "Was not able to get a database dialect.",
1011
"DefaultPlugin.executingMethod": "Executing method: %s",

common/lib/wrapper_property.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,27 @@ export class WrapperProperties {
7171
null
7272
);
7373

74+
/**
75+
* @deprecated since version 1.1.0 and replaced by wrapper property WRAPPER_QUERY_TIMEOUT.
76+
*/
7477
static readonly INTERNAL_QUERY_TIMEOUT = new WrapperProperty<number>(
7578
"mysqlQueryTimeout",
7679
"Timeout in milliseconds for the wrapper to execute queries against MySQL database engines",
7780
20000
7881
);
7982

83+
static readonly WRAPPER_CONNECT_TIMEOUT = new WrapperProperty<number>(
84+
"wrapperConnectTimeout",
85+
"Timeout in milliseconds for the wrapper to create a connection.",
86+
10000
87+
);
88+
89+
static readonly WRAPPER_QUERY_TIMEOUT = new WrapperProperty<number>(
90+
"wrapperQueryTimeout",
91+
"Timeout in milliseconds for the wrapper to execute queries.",
92+
20000
93+
);
94+
8095
static readonly TRANSFER_SESSION_STATE_ON_SWITCH = new WrapperProperty<boolean>(
8196
"transferSessionStateOnSwitch",
8297
"Enables session state transfer to a new connection.",

0 commit comments

Comments
 (0)