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

[feature] Added mysql timeouts to config #474

Merged
merged 1 commit into from
Jun 4, 2024
Merged
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: 4 additions & 1 deletion Common/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@
"idleTimeoutMillis": 30000
}
},
"mysqlExtraOptions": {}
"mysqlExtraOptions": {
"connectTimeout": 60000,
"queryTimeout": 60000
}
},
"redis": {
"name": "redis",
Expand Down
9 changes: 7 additions & 2 deletions DocService/sources/databaseConnectors/mysqlConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ const connectionConfiguration = {

const additionalOptions = configSql.get('mysqlExtraOptions');
const configuration = Object.assign({}, connectionConfiguration, additionalOptions);
let queryTimeout = undefined;
if (configuration.queryTimeout) {
queryTimeout = configuration.queryTimeout;
delete configuration.queryTimeout;
}

let pool = mysql.createPool(configuration);
const pool = mysql.createPool(configuration);

function sqlQuery(ctx, sqlCommand, callbackFunction, opt_noModifyRes = false, opt_noLog = false, opt_values = []) {
return executeQuery(ctx, sqlCommand, opt_values, opt_noModifyRes, opt_noLog).then(
Expand All @@ -68,7 +73,7 @@ async function executeQuery(ctx, sqlCommand, values = [], noModifyRes = false, n
try {
connection = await pool.getConnection();

const result = await connection.query(sqlCommand, values);
const result = await connection.query({ sql: sqlCommand, timeout: queryTimeout, values });

let output;
if (!noModifyRes) {
Expand Down
Loading