Skip to content

Commit f4b0744

Browse files
committed
Merge pull request #715 from dougwilson/fix/pool-long-stack-trace
Fix call site when using Pool.prototype.query
2 parents 6eea20d + f004494 commit f4b0744

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

lib/Pool.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,23 @@ Pool.prototype.query = function (sql, values, cb) {
127127
cb = values;
128128
values = null;
129129
}
130-
130+
131+
var connection;
132+
var query = Connection.createQuery(sql, values, function (err, rows, fields) {
133+
connection.release();
134+
cb.apply(this, arguments);
135+
});
136+
137+
if (this.config.connectionConfig.trace) {
138+
// Long stack trace support
139+
query._callSite = new Error;
140+
}
141+
131142
this.getConnection(function (err, conn) {
132143
if (err) return cb(err);
133144

134-
conn.query(sql, values, function (err, rows, fields) {
135-
conn.release();
136-
cb.apply(this, arguments);
137-
});
145+
connection = conn;
146+
conn.query(query);
138147
});
139148
};
140149

lib/protocol/Protocol.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Protocol.prototype._enqueue = function(sequence) {
107107

108108
if (this._config.trace) {
109109
// Long stack trace support
110-
sequence._callSite = new Error;
110+
sequence._callSite = sequence._callSite || new Error;
111111
}
112112

113113
this._queue.push(sequence);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var pool = common.createPool({connectionLimit: 1});
4+
5+
var err;
6+
pool.getConnection(function(_err, conn) {
7+
if (_err) throw _err;
8+
pool.query('invalid sql', function(_err) {
9+
err = _err;
10+
pool.end();
11+
});
12+
process.nextTick(function() {
13+
conn.release();
14+
});
15+
});
16+
17+
process.on('exit', function() {
18+
assert.ok(err.stack.indexOf(__filename) > 0);
19+
});

0 commit comments

Comments
 (0)