Skip to content

Commit

Permalink
Avoid setting numeric config options to NaN
Browse files Browse the repository at this point in the history
Instead, treat NaN (as well as undefined) as an absent option and use
the default value.

Fixes #721 where a connectionLimit of NaN would render the pool silently
unable to acquire connections.
  • Loading branch information
jleedev committed Dec 3, 2019
1 parent 4938577 commit 73f13bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions lib/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ class ConnectionConfig {
this.password = options.password || undefined;
this.passwordSha1 = options.passwordSha1 || undefined;
this.database = options.database;
this.connectTimeout =
options.connectTimeout === undefined ? 10 * 1000 : options.connectTimeout;
this.connectTimeout = isNaN(options.connectTimeout)
? 10 * 1000
: options.connectTimeout;
this.insecureAuth = options.insecureAuth || false;
this.supportBigNumbers = options.supportBigNumbers || false;
this.bigNumberStrings = options.bigNumberStrings || false;
Expand Down Expand Up @@ -153,7 +154,9 @@ class ConnectionConfig {
let flags = 0x0,
i;
if (!Array.isArray(user_flags)) {
user_flags = String(user_flags || '').toUpperCase().split(/\s*,+\s*/);
user_flags = String(user_flags || '')
.toUpperCase()
.split(/\s*,+\s*/);
}
// add default flags unless "blacklisted"
for (i in default_flags) {
Expand Down
12 changes: 6 additions & 6 deletions lib/pool_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class PoolConfig {
options.waitForConnections === undefined
? true
: Boolean(options.waitForConnections);
this.connectionLimit =
options.connectionLimit === undefined
? 10
: Number(options.connectionLimit);
this.queueLimit =
options.queueLimit === undefined ? 0 : Number(options.queueLimit);
this.connectionLimit = isNaN(options.connectionLimit)
? 10
: Number(options.connectionLimit);
this.queueLimit = isNaN(options.queueLimit)
? 0
: Number(options.queueLimit);
}
}

Expand Down

0 comments on commit 73f13bf

Please sign in to comment.