From fb9105ec1a75dcde8936dcbec3e0d90af4d1aca6 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Thu, 18 Aug 2022 15:02:48 +0100 Subject: [PATCH 1/3] Allow 0 as a request timeout option --- CHANGELOG.txt | 4 ++++ lib/msnodesqlv8/connection-pool.js | 12 ++++++++++-- lib/tedious/connection-pool.js | 12 ++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 0247e3a8..dce009ee 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,7 @@ +v8.1.4 (2022-08-??) +------------------- +[fix] fix regression in requestTimout option not accepting `0` as a value ([#1421](https://github.com/tediousjs/node-mssql/pull/1421)) + v8.1.3 (2022-08-08) ------------------- [fix] requestTimeout correctly resolved ([#1398](https://github.com/tediousjs/node-mssql/pull/1398)) diff --git a/lib/msnodesqlv8/connection-pool.js b/lib/msnodesqlv8/connection-pool.js index 497a2e0e..78de9e18 100644 --- a/lib/msnodesqlv8/connection-pool.js +++ b/lib/msnodesqlv8/connection-pool.js @@ -12,6 +12,14 @@ const CONNECTION_DRIVER = ['darwin', 'linux'].includes(platform()) ? 'ODBC Drive const CONNECTION_STRING_PORT = `Driver=${CONNECTION_DRIVER};Server=#{server},#{port};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};` const CONNECTION_STRING_NAMED_INSTANCE = `Driver=${CONNECTION_DRIVER};Server=#{server}\\#{instance};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};` +function firstDefined () { + for (let i = 0; i < arguments.length; i++) { + if (typeof arguments[i] !== 'undefined') { + return arguments[i] + } + } +} + class ConnectionPool extends BaseConnectionPool { _poolCreate () { return new shared.Promise((resolve, reject) => { @@ -21,11 +29,11 @@ class ConnectionPool extends BaseConnectionPool { defaultConnectionString = CONNECTION_STRING_NAMED_INSTANCE } - this.config.requestTimeout = this.config.requestTimeout || this.config.timeout || 15000 + this.config.requestTimeout = firstDefined(this.config.requestTimeout, this.config.timeout, 15000) const cfg = { conn_str: this.config.connectionString || defaultConnectionString, - conn_timeout: (this.config.connectionTimeout || this.config.timeout || 15000) / 1000 + conn_timeout: firstDefined(this.config.connectionTimeout, this.config.timeout, 15000) / 1000 } cfg.conn_str = cfg.conn_str.replace(/#{([^}]*)}/g, (p) => { diff --git a/lib/tedious/connection-pool.js b/lib/tedious/connection-pool.js index 17c0d3a9..ab2431e2 100644 --- a/lib/tedious/connection-pool.js +++ b/lib/tedious/connection-pool.js @@ -7,6 +7,14 @@ const { IDS } = require('../utils') const shared = require('../shared') const ConnectionError = require('../error/connection-error') +function firstDefined () { + for (let i = 0; i < arguments.length; i++) { + if (typeof arguments[i] !== 'undefined') { + return arguments[i] + } + } +} + class ConnectionPool extends BaseConnectionPool { _poolCreate () { return new shared.Promise((resolve, reject) => { @@ -36,8 +44,8 @@ class ConnectionPool extends BaseConnectionPool { cfg.options.database = cfg.options.database || this.config.database cfg.options.port = cfg.options.port || this.config.port - cfg.options.connectTimeout = cfg.options.connectTimeout || this.config.connectionTimeout || this.config.timeout || 15000 - cfg.options.requestTimeout = cfg.options.requestTimeout || this.config.requestTimeout || this.config.timeout || 15000 + cfg.options.connectTimeout = firstDefined(cfg.options.connectTimeout, this.config.connectionTimeout, this.config.timeout, 15000) + cfg.options.requestTimeout = firstDefined(cfg.options.requestTimeout, this.config.requestTimeout, this.config.timeout, 15000) cfg.options.tdsVersion = cfg.options.tdsVersion || '7_4' cfg.options.rowCollectionOnDone = cfg.options.rowCollectionOnDone || false cfg.options.rowCollectionOnRequestCompletion = cfg.options.rowCollectionOnRequestCompletion || false From 52e34c53ca8465f485fd60e40c8819e0fcf2327f Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Thu, 18 Aug 2022 16:32:28 +0100 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index dce009ee..b7c490fd 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,4 @@ -v8.1.4 (2022-08-??) +v8.1.4 (2022-08-18) ------------------- [fix] fix regression in requestTimout option not accepting `0` as a value ([#1421](https://github.com/tediousjs/node-mssql/pull/1421)) From c5c88b311f5bccf55f9bd5e76e09d25b0669f89a Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Thu, 18 Aug 2022 16:32:34 +0100 Subject: [PATCH 3/3] 8.1.4 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 567b31b3..c7b4ec2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "mssql", - "version": "8.1.3", + "version": "8.1.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 37d0c9ce..d40094f2 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "azure", "node-mssql" ], - "version": "8.1.3", + "version": "8.1.4", "main": "index.js", "repository": "github:tediousjs/node-mssql", "license": "MIT",