Skip to content

Commit

Permalink
Merge branch 'release/2.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jul 1, 2020
2 parents cda6634 + f4e8ed5 commit 38c49b1
Show file tree
Hide file tree
Showing 28 changed files with 535 additions and 179 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ matrix:
allow_failures:
- node_js: "12"
env: DB=build SKIP_LEAK=1
- node_js: "12"
env: SKYSQL=true SKIP_LEAK=1
include:
- node_js: "12"
env: DB=build SKIP_LEAK=1
Expand Down
1 change: 0 additions & 1 deletion .travis/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ RUN dpkg -R --unpack /root/
RUN apt-get install -f -y

RUN rm -rf /var/lib/apt/lists/* \
&& sed -ri 's/^user\s/#&/' /etc/mysql/my.cnf /etc/mysql/conf.d/* \
&& rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \
&& chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \
&& chmod 777 /var/run/mysqld \
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Change Log
## [2.4.1](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/2.4.1) (01 Jul 2020)
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/2.4.0...2.4.1)

* CONJS-138 - pool.getConnection() might not timeout even with acquireTimeout set
* CONJS-139 - createConnection(string)` does not support URL-encoded credentials
* CONJS-140 - Support passing null values in array when doing queries. thanks to @koendeschacht
* CONJS-141 - set default value of option `restoreNodeTimeout` to 1000 to avoid using blacklisted pool in cluster


## [2.4.0](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/2.4.0) (24 May 2020)
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/2.3.1...2.4.0)

Expand Down
21 changes: 8 additions & 13 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,47 @@ environment:
TEST_LOG_PACKETS: true
matrix:

- DB: '10.4.12'
- DB: '10.4.13'
MEM: "21"
nodejs_version: "10"

- DB: '10.4.12'
- DB: '10.4.13'
MEM: "21"
nodejs_version: "12"
SKIP_LEAK: "1"

- DB: '10.4.12'
- DB: '10.4.13'
nodejs_version: "12"
MEM: "21"
TEST_ZIP: 1
SKIP_LEAK: "1"

- DB: '10.4.12'
- DB: '10.4.13'
nodejs_version: "12"
MEM: "21"
BENCH: "1"
SKIP_LEAK: "1"

- DB: '10.5.1'
- DB: '10.5.4'
MEM: "21"
nodejs_version: "12"
SKIP_LEAK: "1"

- DB: '10.3.22'
- DB: '10.3.23'
MEM: "21"
nodejs_version: "12"
SKIP_LEAK: "1"

- DB: '10.2.31'
- DB: '10.2.32'
MEM: "21"
nodejs_version: "12"
SKIP_LEAK: "1"

- DB: '10.1.44'
- DB: '10.1.45'
MEM: "21"
nodejs_version: "12"
SKIP_LEAK: "1"

- DB: '5.5.67'
MEM: "5"
nodejs_version: "12"
SKIP_LEAK: "1"

cache:
- node_modules

Expand Down
2 changes: 1 addition & 1 deletion documentation/callback-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Specific options for pool cluster are :
|---:|---|:---:|:---:|
| **`canRetry`** | When getting a connection from pool fails, can cluster retry with other pools |*boolean* | true |
| **`removeNodeErrorCount`** | Maximum number of consecutive connection fail from a pool before pool is removed from cluster configuration. null means node won't be removed|*integer* | 5 |
| **`restoreNodeTimeout`** | delay before a pool can be reused after a connection fails. 0 = can be reused immediately (in ms) |*integer*| 0|
| **`restoreNodeTimeout`** | delay before a pool can be reused after a connection fails. 0 = can be reused immediately (in ms) |*integer*| 1000|
| **`defaultSelector`** | default pools selector. Can be 'RR' (round-robin), 'RANDOM' or 'ORDER' (use in sequence = always use first pools unless fails) |*string*| 'RR'|
Expand Down
4 changes: 2 additions & 2 deletions documentation/promise-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Specific options for pool cluster are :
|---:|---|:---:|:---:|
| **`canRetry`** | When getting a connection from pool fails, can cluster retry with other pools |*boolean* | true |
| **`removeNodeErrorCount`** | Maximum number of consecutive connection fail from a pool before pool is removed from cluster configuration. null means node won't be removed|*integer* | 5 |
| **`restoreNodeTimeout`** | delay before a pool can be reused after a connection fails. 0 = can be reused immediately (in ms) |*integer*| 0|
| **`restoreNodeTimeout`** | delay before a pool can be reused after a connection fails. 0 = can be reused immediately (in ms) |*integer*| 1000|
| **`defaultSelector`** | default pools selector. Can be 'RR' (round-robin), 'RANDOM' or 'ORDER' (use in sequence = always use first pools unless fails) |*string*| 'RR'|

## `version → String`
Expand Down Expand Up @@ -1278,7 +1278,7 @@ const mariadb = require('mariadb');
const cluster = mariadb.createPoolCluster({ removeNodeErrorCount: 20, restoreNodeTimeout: 5000 });
cluster.add("master", { host: 'mydb1.com', user: 'myUser', connectionLimit: 5 });
cluster.add("slave1", { host: 'mydb2.com', user: 'myUser', connectionLimit: 5 });
cluster.add("slave2", { host: 'mydb3.com', user: 'myUser', connectionLimit: 5 });*
cluster.add("slave2", { host: 'mydb3.com', user: 'myUser', connectionLimit: 5 });
cluster.on('remove', node => {
console.log(`node ${node} was removed`);
})
Expand Down
4 changes: 2 additions & 2 deletions lib/cmd/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ class Command extends EventEmitter {
* @param val return value.
*/
successEnd(val) {
this.onPacketReceive = null;
if (this.resolve) {
this.onPacketReceive = null;
this.reject = null;
process.nextTick(this.resolve, val);
this.resolve = null;
this.emit('end');
}
this.emit('end');
}

static parseOkPacket(packet, out, opts, info) {
Expand Down
4 changes: 3 additions & 1 deletion lib/cmd/common-text-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class CommonText extends ResultSet {
out.writeStringAscii('' + value);
break;
case 'object':
if (Object.prototype.toString.call(value) === '[object Date]') {
if (value === null) {
out.writeStringAscii('NULL');
} else if (Object.prototype.toString.call(value) === '[object Date]') {
out.writeStringAscii(this.getDateQuote(value, opts));
} else if (Buffer.isBuffer(value)) {
out.writeStringAscii("_BINARY '");
Expand Down
7 changes: 1 addition & 6 deletions lib/cmd/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,8 @@ class Query extends CommonText {
for (let i = 1; i < len; i++) {
const value = this.values[i - 1];

if (value === null) {
out.writeStringAscii('NULL');
out.writeString(this.queryParts[i]);
continue;
}

if (
value !== null &&
typeof value === 'object' &&
typeof value.pipe === 'function' &&
typeof value.read === 'function'
Expand Down
14 changes: 8 additions & 6 deletions lib/config/connection-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ConnectionOptions {
opts.charsetNumber = Number.parseInt(opts.charsetNumber);
}
if (opts.compress) opts.compress = opts.compress == 'true';
if (opts.connectAttributes) opts.connectAttributes = opts.connectAttributes == 'true';
if (opts.connectAttributes) opts.connectAttributes = JSON.parse(opts.connectAttributes);
if (opts.connectTimeout) opts.connectTimeout = parseInt(opts.connectTimeout);
if (opts.socketTimeout) opts.socketTimeout = parseInt(opts.socketTimeout);
if (opts.dateStrings) opts.dateStrings = opts.dateStrings == 'true';
Expand Down Expand Up @@ -208,11 +208,11 @@ class ConnectionOptions {
);
}
const options = {
user: matchResults[2],
password: matchResults[4],
host: matchResults[6],
user: matchResults[2] ? decodeURIComponent(matchResults[2]) : undefined,
password: matchResults[4] ? decodeURIComponent(matchResults[4]) : undefined,
host: matchResults[6] ? decodeURIComponent(matchResults[6]) : matchResults[6],
port: matchResults[8] ? parseInt(matchResults[8]) : undefined,
database: matchResults[9]
database: matchResults[9] ? decodeURIComponent(matchResults[9]) : matchResults[9]
};

const variousOptsString = matchResults[11];
Expand All @@ -221,7 +221,9 @@ class ConnectionOptions {
keyVals.forEach(function (keyVal) {
const equalIdx = keyVal.indexOf('=');
if (equalIdx !== 1) {
options[keyVal.substring(0, equalIdx)] = keyVal.substring(equalIdx + 1);
let val = keyVal.substring(equalIdx + 1);
val = val ? decodeURIComponent(val) : undefined;
options[keyVal.substring(0, equalIdx)] = val;
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/config/pool-cluster-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class PoolClusterOptions {
if (opts) {
this.canRetry = opts.canRetry === undefined ? true : opts.canRetry;
this.removeNodeErrorCount = opts.removeNodeErrorCount || 5;
this.restoreNodeTimeout = opts.restoreNodeTimeout || 0;
this.restoreNodeTimeout = opts.restoreNodeTimeout || 1000;
this.defaultSelector = opts.defaultSelector || 'RR';
} else {
this.canRetry = true;
this.removeNodeErrorCount = 5;
this.restoreNodeTimeout = 0;
this.restoreNodeTimeout = 1000;
this.defaultSelector = 'RR';
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/config/pool-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PoolOptions {
if (opts.minimumIdle) opts.minimumIdle = parseInt(opts.minimumIdle);
if (opts.noControlAfterUse) opts.noControlAfterUse = opts.noControlAfterUse == 'true';
if (opts.resetAfterUse) opts.resetAfterUse = opts.resetAfterUse == 'true';
if (opts.pingTimeout) opts.pingTimeout = parseInt(opts.pingTimeout);
}

this.acquireTimeout = opts.acquireTimeout === undefined ? 10000 : opts.acquireTimeout;
Expand All @@ -34,7 +35,7 @@ class PoolOptions {
: Math.min(opts.minimumIdle, this.connectionLimit);
this.noControlAfterUse = opts.noControlAfterUse || false;
this.resetAfterUse = opts.resetAfterUse === undefined ? true : opts.resetAfterUse;

this.pingTimeout = opts.pingTimeout || 250;
this.connOptions = new ConnOptions(opts);

if (this.acquireTimeout > 0 && this.connOptions.connectTimeout > this.acquireTimeout) {
Expand Down
16 changes: 12 additions & 4 deletions lib/connection-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ function ConnectionCallback(options) {
.catch(callback || emptyError);
};

const _pingCallback = (callback) => {
pingPromise()
.then(callback || emptySuccess)
.catch(callback || emptyError);
const _pingCallback = (timeout, callback) => {
let _timeout, _cb;
if (typeof timeout === 'function') {
_cb = timeout;
_timeout = undefined;
} else {
_timeout = timeout;
_cb = callback;
}
pingPromise(_timeout)
.then(_cb || emptySuccess)
.catch(_cb || emptyError);
};

const _resetCallback = (callback) => {
Expand Down
42 changes: 40 additions & 2 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,49 @@ function Connection(options) {

/**
* Send an empty MySQL packet to ensure connection is active, and reset @@wait_timeout
*
* @param timeout (optional) timeout value in ms. If reached, throw error and close connection
* @returns {Promise} promise
*/
this.ping = () => {
this.ping = (timeout) => {
return new Promise(function (resolve, reject) {
if (timeout) {
if (timeout < 0) {
reject(
Errors.createError(
'Ping cannot have negative timeout value',
false,
info,
'0A000',
Errors.ER_BAD_PARAMETER_VALUE
)
);
return;
}
const tOut = setTimeout(() => {
reject(Errors.createError('Ping timeout', true, info, '0A000', Errors.ER_PING_TIMEOUT));
// close connection
_addCommand = _addCommandDisabled;
clearTimeout(_timeout);
if (_status !== Status.CLOSING && _status !== Status.CLOSED) {
_sendQueue.clear();
_status = Status.CLOSED;
_socket.destroy();
}
_clear();
}, timeout);
return _addCommand(
new Ping(
() => {
clearTimeout(tOut);
resolve();
},
(err) => {
clearTimeout(tOut);
reject(err);
}
)
);
}
return _addCommand(new Ping(resolve, reject));
});
};
Expand Down
2 changes: 2 additions & 0 deletions lib/misc/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ module.exports.ER_TIMEOUT_NOT_SUPPORTED = 45038;
module.exports.ER_INITIAL_TIMEOUT_ERROR = 45039;
module.exports.ER_DUPLICATE_FIELD = 45040;
module.exports.ER_CLIENT_OPTION_INCOMPATIBILITY = 45041;
module.exports.ER_PING_TIMEOUT = 45042;
module.exports.ER_BAD_PARAMETER_VALUE = 45043;

const keys = Object.keys(module.exports);
const errByNo = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/pool-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function PoolCallback(options) {

const pingPromise = function (conn) {
return new Promise((resolve, reject) => {
conn.ping((err) => {
conn.ping(options.pingTimeout, (err) => {
if (err) {
reject(err);
} else resolve();
Expand Down
2 changes: 1 addition & 1 deletion lib/pool-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function PoolPromise(options) {
};

PoolBase.call(this, options, processTaskPromise, createConnectionPoolPromise, (conn) =>
conn.ping()
conn.ping(options.pingTimeout)
);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mariadb",
"version": "2.4.0",
"version": "2.4.1",
"description": "fast mariadb/mysql connector.",
"main": "promise.js",
"types": "types/index.d.ts",
Expand Down
Loading

0 comments on commit 38c49b1

Please sign in to comment.