From 936b5a4d4a1733ca08edb41221b952efe26ba288 Mon Sep 17 00:00:00 2001 From: Georgii Petrov Date: Thu, 1 Feb 2024 15:29:25 +0300 Subject: [PATCH 1/2] [config] Set dameng, oracle and mssql databases connectors timeouts to limited values --- Common/config/default.json | 13 +++++++++-- .../databaseConnectors/mssqlConnector.js | 23 +++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Common/config/default.json b/Common/config/default.json index 8d120fbfd..94f42bd16 100644 --- a/Common/config/default.json +++ b/Common/config/default.json @@ -186,14 +186,23 @@ "damengExtraOptions": { "columnNameUpperCase": false, "columnNameCase": "lower", + "connectTimeout": 60000, "loginEncrypt": false, - "localTimezone": 0 + "localTimezone": 0, + "poolTimeout": 60, + "socketTimeout": 60000, + "queueTimeout": 60000 + }, + "oracleExtraOptions": { + "connectTimeout": 60 }, - "oracleExtraOptions": {}, "msSqlExtraOptions": { "options": { "encrypt": false, "trustServerCertificate": true + }, + "pool": { + "idleTimeoutMillis": 3000 } } }, diff --git a/DocService/sources/databaseConnectors/mssqlConnector.js b/DocService/sources/databaseConnectors/mssqlConnector.js index d89a277a8..e77f208dc 100644 --- a/DocService/sources/databaseConnectors/mssqlConnector.js +++ b/DocService/sources/databaseConnectors/mssqlConnector.js @@ -32,7 +32,7 @@ 'use strict'; -const sql = require("mssql"); +const sql = require('mssql'); const config = require('config'); const connectorUtilities = require('./connectorUtilities'); const utils = require('../../../Common/sources/utils'); @@ -50,12 +50,21 @@ const connectionConfiguration = { database: configSql.get('dbName'), pool: { max: configSql.get('connectionlimit'), - min: 0, - idleTimeoutMillis: 30000 + min: 0 } }; const additionalOptions = configSql.get('msSqlExtraOptions'); -const configuration = Object.assign({}, connectionConfiguration, additionalOptions); + +const mergedObjects = {}; +for (const option in additionalOptions) { + if (connectionConfiguration.hasOwnProperty(option) && typeof connectionConfiguration[option] === 'object') { + mergedObjects[option] = Object.assign({}, connectionConfiguration[option], additionalOptions[option]); + } else { + mergedObjects[option] = additionalOptions[option]; + } +} + +const configuration = Object.assign({}, connectionConfiguration, mergedObjects); const placeholderPrefix = 'ph_'; @@ -72,15 +81,15 @@ function errorHandle(message, error, ctx) { function dataType(value) { let type = sql.TYPES.NChar(1); switch (typeof value) { - case "number": { + case 'number': { type = sql.TYPES.Decimal(18, 0); break; } - case "string": { + case 'string': { type = sql.TYPES.NVarChar(sql.MAX); break; } - case "object": { + case 'object': { if (value instanceof Date) { type = sql.TYPES.DateTime(); } From ff8dd6433def92dcfb701402e14577d6ddae2fa8 Mon Sep 17 00:00:00 2001 From: Georgii Petrov Date: Thu, 1 Feb 2024 16:55:15 +0300 Subject: [PATCH 2/2] [utils] deepMergeObjecs(), isObject() functions added --- Common/config/default.json | 4 +-- Common/sources/utils.js | 29 +++++++++++++++++++ .../databaseConnectors/mssqlConnector.js | 12 +------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Common/config/default.json b/Common/config/default.json index 94f42bd16..d1416644d 100644 --- a/Common/config/default.json +++ b/Common/config/default.json @@ -177,7 +177,7 @@ "connectionlimit": 10, "max_allowed_packet": 1048575, "pgPoolExtraOptions": { - "idleTimeoutMillis": 3000, + "idleTimeoutMillis": 30000, "maxLifetimeSeconds ": 60000, "statement_timeout ": 60000, "query_timeout ": 60000, @@ -202,7 +202,7 @@ "trustServerCertificate": true }, "pool": { - "idleTimeoutMillis": 3000 + "idleTimeoutMillis": 30000 } } }, diff --git a/Common/sources/utils.js b/Common/sources/utils.js index 3b02a5f9f..811d571dd 100644 --- a/Common/sources/utils.js +++ b/Common/sources/utils.js @@ -1111,3 +1111,32 @@ exports.checksumFile = function(hashName, path) { stream.on('end', () => resolve(hash.digest('hex'))); }); }; + +function isObject(item) { + return (item && typeof item === 'object' && !Array.isArray(item)); +} + +function deepMergeObjects(target, ...sources) { + if (!sources.length) { + return target; + } + + const source = sources.shift(); + if (isObject(target) && isObject(source)) { + for (const key in source) { + if (isObject(source[key])) { + if (!target[key]) { + Object.assign(target, { [key]: {} }); + } + + deepMergeObjects(target[key], source[key]); + } else { + Object.assign(target, { [key]: source[key] }); + } + } + } + + return deepMergeObjects(target, ...sources); +} +exports.isObject = isObject; +exports.deepMergeObjects = deepMergeObjects; \ No newline at end of file diff --git a/DocService/sources/databaseConnectors/mssqlConnector.js b/DocService/sources/databaseConnectors/mssqlConnector.js index e77f208dc..638118035 100644 --- a/DocService/sources/databaseConnectors/mssqlConnector.js +++ b/DocService/sources/databaseConnectors/mssqlConnector.js @@ -54,17 +54,7 @@ const connectionConfiguration = { } }; const additionalOptions = configSql.get('msSqlExtraOptions'); - -const mergedObjects = {}; -for (const option in additionalOptions) { - if (connectionConfiguration.hasOwnProperty(option) && typeof connectionConfiguration[option] === 'object') { - mergedObjects[option] = Object.assign({}, connectionConfiguration[option], additionalOptions[option]); - } else { - mergedObjects[option] = additionalOptions[option]; - } -} - -const configuration = Object.assign({}, connectionConfiguration, mergedObjects); +const configuration = utils.deepMergeObjects({}, connectionConfiguration, additionalOptions); const placeholderPrefix = 'ph_';