Skip to content

Commit

Permalink
Allow 0 as a request timeout option
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Aug 18, 2022
1 parent 9c9e6ca commit fb9105e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
12 changes: 10 additions & 2 deletions lib/msnodesqlv8/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down
12 changes: 10 additions & 2 deletions lib/tedious/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb9105e

Please sign in to comment.