diff --git a/Common/config/default.json b/Common/config/default.json index 170d3868f..80bc963d9 100644 --- a/Common/config/default.json +++ b/Common/config/default.json @@ -241,7 +241,10 @@ "idleTimeoutMillis": 30000 } }, - "mysqlExtraOptions": {} + "mysqlExtraOptions": { + "connectTimeout": 60000, + "queryTimeout": 60000 + } }, "redis": { "name": "redis", diff --git a/DocService/sources/databaseConnectors/mysqlConnector.js b/DocService/sources/databaseConnectors/mysqlConnector.js index d46d4511b..1c2103b52 100644 --- a/DocService/sources/databaseConnectors/mysqlConnector.js +++ b/DocService/sources/databaseConnectors/mysqlConnector.js @@ -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( @@ -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) {