From c1553c0f7ad6133a0a2373763632fdd8278d27dc Mon Sep 17 00:00:00 2001 From: Sergey Konovalov Date: Wed, 31 Jan 2024 20:56:47 +0300 Subject: [PATCH] [config] Set pg connector timeouts to limited values; Bump pg version --- Common/config/default.json | 8 +++++++- DocService/npm-shrinkwrap.json | 19 +++++++++++++------ DocService/package.json | 2 +- .../databaseConnectors/postgreConnector.js | 9 +++++++-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Common/config/default.json b/Common/config/default.json index 87d389a2..8d120fbf 100644 --- a/Common/config/default.json +++ b/Common/config/default.json @@ -176,7 +176,13 @@ "charset": "utf8", "connectionlimit": 10, "max_allowed_packet": 1048575, - "pgPoolExtraOptions": {}, + "pgPoolExtraOptions": { + "idleTimeoutMillis": 3000, + "maxLifetimeSeconds ": 60000, + "statement_timeout ": 60000, + "query_timeout ": 60000, + "connectionTimeoutMillis": 60000 + }, "damengExtraOptions": { "columnNameUpperCase": false, "columnNameCase": "lower", diff --git a/DocService/npm-shrinkwrap.json b/DocService/npm-shrinkwrap.json index 4b1cb3a1..91fd5adf 100644 --- a/DocService/npm-shrinkwrap.json +++ b/DocService/npm-shrinkwrap.json @@ -2716,19 +2716,26 @@ "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" }, "pg": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/pg/-/pg-8.8.0.tgz", - "integrity": "sha512-UXYN0ziKj+AeNNP7VDMwrehpACThH7LUl/p8TDFpEUuSejCUIwGSfxpHsPvtM6/WXFy6SU4E5RG4IJV/TZAGjw==", + "version": "8.11.3", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.11.3.tgz", + "integrity": "sha512-+9iuvG8QfaaUrrph+kpF24cXkH1YOOUeArRNYIxq1viYHZagBxrTno7cecY1Fa44tJeZvaoG+Djpkc3JwehN5g==", "requires": { "buffer-writer": "2.0.0", "packet-reader": "1.0.0", - "pg-connection-string": "^2.5.0", - "pg-pool": "^3.5.2", - "pg-protocol": "^1.5.0", + "pg-cloudflare": "^1.1.1", + "pg-connection-string": "^2.6.2", + "pg-pool": "^3.6.1", + "pg-protocol": "^1.6.0", "pg-types": "^2.1.0", "pgpass": "1.x" } }, + "pg-cloudflare": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz", + "integrity": "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==", + "optional": true + }, "pg-connection-string": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.6.2.tgz", diff --git a/DocService/package.json b/DocService/package.json index ebd7f67c..c8342474 100644 --- a/DocService/package.json +++ b/DocService/package.json @@ -37,7 +37,7 @@ "multiparty": "4.2.1", "mysql2": "2.3.3", "oracledb": "6.0.1", - "pg": "8.8.0", + "pg": "8.11.3", "redis": "4.6.11", "retry": "0.12.0", "socket.io": "4.7.1", diff --git a/DocService/sources/databaseConnectors/postgreConnector.js b/DocService/sources/databaseConnectors/postgreConnector.js index 349a5f81..f92de249 100644 --- a/DocService/sources/databaseConnectors/postgreConnector.js +++ b/DocService/sources/databaseConnectors/postgreConnector.js @@ -36,6 +36,7 @@ var pg = require('pg'); var co = require('co'); var types = require('pg').types; const connectorUtilities = require('./connectorUtilities'); +const operationContext = require('../../../Common/sources/operationContext'); const config = require('config'); var configSql = config.get('services.CoAuthoring.sql'); const cfgTableResult = config.get('services.CoAuthoring.sql.tableResult'); @@ -50,12 +51,16 @@ let connectionConfig = { database: configSql.get('dbName'), max: configSql.get('connectionlimit'), min: 0, - ssl: false, - idleTimeoutMillis: 30000 + ssl: false }; //clone pgPoolExtraOptions to resolve 'TypeError: Cannot redefine property: key' in pg-pool +//timeouts from https://github.com/brianc/node-postgres/issues/3018#issuecomment-1619729794 config.util.extendDeep(connectionConfig, pgPoolExtraOptions); var pool = new pg.Pool(connectionConfig); +//listen "error" event otherwise - unhandled exception(https://github.com/brianc/node-postgres/issues/2764#issuecomment-1163475426) +pool.on('error', (err, client) => { + operationContext.global.logger.error(`postgresql pool error %s`, err.stack) +}) //todo datetime timezone pg.defaults.parseInputDatesAsUTC = true; types.setTypeParser(1114, function(stringValue) {