Skip to content

Commit

Permalink
Merge pull request #453 from ONLYOFFICE/fix/databases-timeout
Browse files Browse the repository at this point in the history
Fix/databases timeout
  • Loading branch information
konovalovsergey committed Feb 1, 2024
2 parents c1553c0 + ff8dd64 commit 0d5b109
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
15 changes: 12 additions & 3 deletions Common/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"connectionlimit": 10,
"max_allowed_packet": 1048575,
"pgPoolExtraOptions": {
"idleTimeoutMillis": 3000,
"idleTimeoutMillis": 30000,
"maxLifetimeSeconds ": 60000,
"statement_timeout ": 60000,
"query_timeout ": 60000,
Expand All @@ -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": 30000
}
}
},
Expand Down
29 changes: 29 additions & 0 deletions Common/sources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
13 changes: 6 additions & 7 deletions DocService/sources/databaseConnectors/mssqlConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -50,12 +50,11 @@ 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 configuration = utils.deepMergeObjects({}, connectionConfiguration, additionalOptions);

const placeholderPrefix = 'ph_';

Expand All @@ -72,15 +71,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();
}
Expand Down

0 comments on commit 0d5b109

Please sign in to comment.