diff --git a/lib/Pool.js b/lib/Pool.js index f751f95d7..28a517f9c 100644 --- a/lib/Pool.js +++ b/lib/Pool.js @@ -127,14 +127,23 @@ Pool.prototype.query = function (sql, values, cb) { cb = values; values = null; } - + + var connection; + var query = Connection.createQuery(sql, values, function (err, rows, fields) { + connection.release(); + cb.apply(this, arguments); + }); + + if (this.config.connectionConfig.trace) { + // Long stack trace support + query._callSite = new Error; + } + this.getConnection(function (err, conn) { if (err) return cb(err); - conn.query(sql, values, function (err, rows, fields) { - conn.release(); - cb.apply(this, arguments); - }); + connection = conn; + conn.query(query); }); }; diff --git a/lib/protocol/Protocol.js b/lib/protocol/Protocol.js index a087cc7d6..138e1f3eb 100644 --- a/lib/protocol/Protocol.js +++ b/lib/protocol/Protocol.js @@ -107,7 +107,7 @@ Protocol.prototype._enqueue = function(sequence) { if (this._config.trace) { // Long stack trace support - sequence._callSite = new Error; + sequence._callSite = sequence._callSite || new Error; } this._queue.push(sequence); diff --git a/test/integration/pool/test-long-stack-traces.js b/test/integration/pool/test-long-stack-traces.js new file mode 100644 index 000000000..b910a80b1 --- /dev/null +++ b/test/integration/pool/test-long-stack-traces.js @@ -0,0 +1,19 @@ +var assert = require('assert'); +var common = require('../../common'); +var pool = common.createPool({connectionLimit: 1}); + +var err; +pool.getConnection(function(_err, conn) { + if (_err) throw _err; + pool.query('invalid sql', function(_err) { + err = _err; + pool.end(); + }); + process.nextTick(function() { + conn.release(); + }); +}); + +process.on('exit', function() { + assert.ok(err.stack.indexOf(__filename) > 0); +});