Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setQueryTimeout for mysql2DriverDialect #393

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions common/lib/mysql_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ export class MySQLClientWrapper implements ClientWrapper {
}

query(sql: any): Promise<any> {
this.driverDialect.setQueryTimeout(this.properties, sql);
return this.client?.query(sql);
const query = { sql: sql };
this.driverDialect.setQueryTimeout(this.properties, query);
return this.client?.query(query);
}

async queryWithTimeout(sql: string): Promise<any> {
Expand Down
19 changes: 1 addition & 18 deletions mysql/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,7 @@ export class AwsMySQLClient extends AwsClient {
}

async query(options: QueryOptions, callback?: any): Promise<Query> {
if (!this.isConnected) {
await this.connect(); // client.connect is not required for MySQL clients
this.isConnected = true;
}
const host = this.pluginService.getCurrentHostInfo();
const context = this.telemetryFactory.openTelemetryContext("awsClient.query", TelemetryTraceLevel.TOP_LEVEL);
return await context.start(async () => {
return await this.pluginManager.execute(
host,
this.properties,
"query",
async () => {
await this.pluginService.updateState(options.sql);
return await ClientUtils.queryWithTimeout(this.targetClient?.client?.query(options, callback), this.properties);
},
options
);
});
return await this.targetClient?.client?.query(options, callback);
}

private async queryWithoutUpdate(options: QueryOptions, callback?: any): Promise<Query> {
Expand Down
2 changes: 1 addition & 1 deletion mysql/lib/dialect/mysql2_driver_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class MySQL2DriverDialect implements DriverDialect {
setQueryTimeout(props: Map<string, any>, sql?: any, wrapperConnectTimeout?: any) {
const timeout = wrapperConnectTimeout ?? props.get(WrapperProperties.WRAPPER_QUERY_TIMEOUT.name);
if (timeout && !sql[MySQL2DriverDialect.QUERY_TIMEOUT_PROPERTY_NAME]) {
sql[MySQL2DriverDialect.QUERY_TIMEOUT_PROPERTY_NAME] = timeout;
sql[MySQL2DriverDialect.QUERY_TIMEOUT_PROPERTY_NAME] = Number(timeout);
}
}

Expand Down
19 changes: 8 additions & 11 deletions mysql/lib/dialect/mysql_database_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,14 @@ export class MySQLDatabaseDialect implements DatabaseDialect {

async isClientValid(targetClient: ClientWrapper): Promise<boolean> {
try {
return await ClientUtils.queryWithTimeout(
targetClient
.query({ sql: "SELECT 1" })
.then(() => {
return true;
})
.catch(() => {
return false;
}),
targetClient.properties
);
return await targetClient
.query("SELECT 1")
.then(() => {
return true;
})
.catch(() => {
return false;
});
} catch (error) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion pg/lib/dialect/node_postgres_driver_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class NodePostgresDriverDialect implements DriverDialect {
}
}

setQueryTimeout(props: Map<string, any>, sql?: any, wrapperQueryTimeout?: any) {
setQueryTimeout(props: Map<string, any>, wrapperQueryTimeout?: any) {
const timeout = wrapperQueryTimeout ?? props.get(WrapperProperties.WRAPPER_QUERY_TIMEOUT.name);
if (timeout) {
props.set(NodePostgresDriverDialect.QUERY_TIMEOUT_PROPERTY_NAME, timeout);
Expand Down