diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b9c0b5e..6d3aedd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Change Log +## [2.3.1](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/2.3.1) (19 Mar. 2020) +[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/2.3.0...2.3.1) + +Corrective release of 2.3.0, changing new connection option `timeout` to `queryTimeout` to avoid any confusion. + ## [2.3.0](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/2.3.0) (19 Mar. 2020) [Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/2.2.0...2.3.0) * CONJS-127 - Resultset with same identifier skip data. Now an error will be thrown. diff --git a/documentation/callback-api.md b/documentation/callback-api.md index d673bc2b..8a59bd04 100644 --- a/documentation/callback-api.md +++ b/documentation/callback-api.md @@ -193,6 +193,7 @@ Essential options list: | **`compress`** | Compresses the exchange with the database through gzip. This permits better performance when the database is not in the same location. |*boolean*| false| | **`connectTimeout`** | Sets the connection timeout in milliseconds. |*integer* | 10 000| | **`socketTimeout`** | Sets the socket timeout in milliseconds after connection succeeds. A value of `0` disables the timeout. |*integer* | 0| +| **`queryTimeout`** | Set maximum query time in ms (an error will be thrown if limit is reached). 0 or undefined meaning no timeout. This can be superseded for a query using `timeout` option|*int* |0| | **`rowsAsArray`** | Returns result-sets as arrays, rather than JSON. This is a faster way to get results. For more information, see Query. |*boolean* | false| For more information, see the [Connection Options](/documentation/connection-options.md) documentation. diff --git a/documentation/connection-options.md b/documentation/connection-options.md index 7f2bf9f1..0f151a93 100644 --- a/documentation/connection-options.md +++ b/documentation/connection-options.md @@ -337,7 +337,6 @@ mariadb.createConnection({ | **collation** | (used in replacement of charset) Permit to defined collation used for connection. This will defined the charset encoding used for exchanges with database and defines the order used when comparing strings. It's mainly used for micro-optimizations|*string* |UTF8MB4_UNICODE_CI| | **dateStrings** | Whether to retrieve dates as strings or as `Date` objects. |*boolean* |false| | **debug** | Logs all exchanges with the server. Displays in hexa.|*boolean* |false| -| **timeout** | Set maximum query time in ms. 0 / undefined meaning no timeout|*int* |0| | **foundRows** | When enabled, the update number corresponds to update rows. When disabled, it indicates the real rows changed. | *boolean* |true| | **multipleStatements** | Allows you to issue several SQL statements in a single `quer()` call. (That is, `INSERT INTO a VALUES('b'); INSERT INTO c VALUES('d');`).

This may be a **security risk** as it allows for SQL Injection attacks. |*boolean* |false| | **namedPlaceholders** | Allows the use of named placeholders. |*boolean* |false| diff --git a/documentation/promise-api.md b/documentation/promise-api.md index f2449462..05b69524 100644 --- a/documentation/promise-api.md +++ b/documentation/promise-api.md @@ -205,6 +205,7 @@ Essential options list: | **`compress`** | Compresses the exchange with the database through gzip. This permits better performance when the database is not in the same location. |*boolean*| false| | **`connectTimeout`** | Sets the connection timeout in milliseconds. |*integer* | 10 000| | **`socketTimeout`** | Sets the socket timeout in milliseconds after connection succeeds. A value of `0` disables the timeout. |*integer* | 0| +| **`queryTimeout`** | Set maximum query time in ms (an error will be thrown if limit is reached). 0 or undefined meaning no timeout. This can be superseded for a query using [`timeout`](https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/master/documentation/promise-api.md#timeout) option|*int* |0| | **`rowsAsArray`** | Returns result-sets as arrays, rather than JSON. This is a faster way to get results. For more information, see Query. |*boolean* | false| For more information, see the [Connection Options](/documentation/connection-options.md) documentation. diff --git a/lib/cmd/resultset.js b/lib/cmd/resultset.js index ecf52c00..233aed43 100644 --- a/lib/cmd/resultset.js +++ b/lib/cmd/resultset.js @@ -89,8 +89,6 @@ class ResultSet extends Command { configAssign(connOpts, cmdOpts) { if (!cmdOpts) { this.opts = connOpts; - // we only need add timeout if needed - this.opts.timeout = 0; return; } this.opts = { diff --git a/lib/config/connection-options.js b/lib/config/connection-options.js index 2bf4781c..7e5a9d45 100644 --- a/lib/config/connection-options.js +++ b/lib/config/connection-options.js @@ -52,7 +52,7 @@ class ConnectionOptions { this.logPackets = opts.logPackets || false; this.connectAttributes = opts.connectAttributes || false; this.connectTimeout = opts.connectTimeout === undefined ? 10000 : opts.connectTimeout; - this.timeout = opts.timeout === undefined ? 0 : opts.timeout; + this.queryTimeout = opts.queryTimeout === undefined ? 0 : opts.queryTimeout; this.socketTimeout = opts.socketTimeout === undefined ? 0 : opts.socketTimeout; this.database = opts.database; this.checkDuplicate = opts.checkDuplicate === undefined ? true : opts.checkDuplicate; @@ -175,7 +175,7 @@ class ConnectionOptions { if (opts.checkDuplicate) opts.checkDuplicate = opts.checkDuplicate == 'true'; if (opts.debugCompress) opts.debugCompress = opts.debugCompress == 'true'; if (opts.debugLen) opts.debugLen = parseInt(opts.debugLen); - if (opts.timeout) opts.timeout = parseInt(opts.timeout); + if (opts.queryTimeout) opts.queryTimeout = parseInt(opts.queryTimeout); if (opts.foundRows) opts.foundRows = opts.foundRows == 'true'; if (opts.maxAllowedPacket && !isNaN(Number.parseInt(opts.maxAllowedPacket))) opts.maxAllowedPacket = parseInt(opts.maxAllowedPacket); diff --git a/lib/connection.js b/lib/connection.js index 3220970f..b40493c7 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -811,13 +811,13 @@ function Connection(options) { }; const _executeSessionTimeout = () => { - if (opts.timeout) { + if (opts.queryTimeout) { if (info.isMariaDB() && info.hasMinVersion(10, 1, 2)) { return new Promise(function(resolve, reject) { const errorHandling = initialErr => { reject( Errors.createError( - 'Error setting session timeout: ' + initialErr.message, + 'Error setting session queryTimeout: ' + initialErr.message, true, info, '08S01', @@ -831,7 +831,7 @@ function Connection(options) { errorHandling, null, opts, - 'SET max_statement_time=' + opts.timeout / 1000, + 'SET max_statement_time=' + opts.queryTimeout / 1000, null ); if (opts.trace) Error.captureStackTrace(cmd); @@ -840,7 +840,8 @@ function Connection(options) { } else { return Promise.reject( Errors.createError( - 'Can only use timeout for MariaDB server after 10.1.1. timeout value: ' + opts.timeout, + 'Can only use queryTimeout for MariaDB server after 10.1.1. queryTimeout value: ' + + opts.queryTimeout, false, info, 'HY000', diff --git a/package.json b/package.json index 1ae07b3c..43bebca7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mariadb", - "version": "2.3.0", + "version": "2.3.1", "description": "fast mariadb/mysql connector.", "main": "promise.js", "types": "types/index.d.ts", diff --git a/test/base.js b/test/base.js index d8043f8e..6de86784 100644 --- a/test/base.js +++ b/test/base.js @@ -4,6 +4,7 @@ const basePromise = require('../promise'); const baseCallback = require('../callback'); const Conf = require('./conf'); const Collations = require('../lib/const/collations.js'); +const { assert } = require('chai'); //***************************************************************** // initialize share connection diff --git a/test/integration/test-connection-opts.js b/test/integration/test-connection-opts.js index 7edb133c..c6aadf72 100644 --- a/test/integration/test-connection-opts.js +++ b/test/integration/test-connection-opts.js @@ -409,7 +409,7 @@ describe('connection option', () => { this.timeout(10000); if (shareConn.info.isMariaDB() && shareConn.info.hasMinVersion(10, 1, 2)) { base - .createConnection({ multipleStatements: true, timeout: 1000 }) + .createConnection({ multipleStatements: true, queryTimeout: 1000 }) .then(conn => { conn .query( @@ -448,4 +448,32 @@ describe('connection option', () => { }); } }); + + it('connection timeout superseded', function(done) { + this.timeout(10000); + if (shareConn.info.isMariaDB() && shareConn.info.hasMinVersion(10, 1, 2)) { + base + .createConnection({ multipleStatements: true, queryTimeout: 10000000 }) + .then(conn => { + conn + .query({ + timeout: 1000, + sql: + 'SELECT 1;select c1.* from information_schema.columns as c1, information_schema.tables, information_schema.tables as t2' + }) + .then(() => { + conn.end(); + done(new Error('must have thrown error')); + }) + .catch(err => { + assert.equal(err.errno, 1969); + assert.equal(err.sqlState, '70100'); + assert.equal(err.code, 'ER_STATEMENT_TIMEOUT'); + conn.end(); + done(); + }); + }) + .catch(done); + } + }); });