Skip to content

release pool connection restores pool user configuration #837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
b85d1e6
release pool connection restores pool user configuration
seangarner May 30, 2014
0d7a863
emit new connection when restoring user
seangarner May 30, 2014
dd01cb2
moved restoreUser onto Pool proto
seangarner Jun 1, 2014
c884488
fix changeUser test for node 0.8
seangarner Jun 1, 2014
f1c8505
Update readme and changes
seangarner Jun 1, 2014
4ea53a0
Add code POOL_NOEXIST in PoolCluster error
quibusus Jun 9, 2014
07dc660
docs: fix typo in code in readme
dougwilson Jul 5, 2014
6cc5c24
Return Query object from pool.query like conn.query
dougwilson Jul 5, 2014
8c78e8b
Use EventEmitter.listenerCount when possible
dougwilson Jul 5, 2014
c3e7a13
Default connectTimeout to 10 seconds
dougwilson Jul 5, 2014
98c2b7f
Fix domain for connection.connect
dougwilson Jul 6, 2014
45aeae2
Add timeout option to all sequences
dougwilson Jul 6, 2014
853bb4b
Add acquireTimeout pool option
dougwilson Jul 6, 2014
439236a
Remove old compatibility layer in Buffer-to-string
dougwilson Jul 6, 2014
be6342d
Fix PROTOCOL_PACKETS_OUT_OF_ORDER error to be catchable
dougwilson Jul 6, 2014
4eb0b45
Add connection.escapeId and pool.escapeId helpers
dougwilson Jul 7, 2014
1d196d5
tests: reorganize tests into unit/integration
dougwilson Jul 6, 2014
98fd2ee
docs: remove completed item from TODO
dougwilson Jul 13, 2014
f2df9c7
Use acquireTimeout for connection handshake timeout
dougwilson Jul 13, 2014
b5a9eb8
Parse default field of field packet correctly
dougwilson Jul 13, 2014
87f1078
Make errors from the parser catchable
dougwilson Jul 13, 2014
91b3467
Include packets that failed parsing under debug
dougwilson Jul 13, 2014
bc54aac
build: minor package.json clean up
dougwilson Jul 13, 2014
65b217e
2.4.0
dougwilson Jul 13, 2014
66ece32
build: add coverage reporting with istanbul
dougwilson Jul 13, 2014
2be5ae4
Fix pool.query not invoking callback on connection error
dougwilson Jul 17, 2014
efb10ca
2.4.1
dougwilson Jul 17, 2014
2d07fbf
Fix timing of fatal protocol errors bubbling to user
dougwilson Aug 3, 2014
cb127ef
tests: improve timeout tests
dougwilson Aug 4, 2014
f6a2209
Fix stray protocol packet errors to be catchable
dougwilson Aug 4, 2014
a0cb232
Fix incorrect sequence packet errors to be catchable
dougwilson Aug 4, 2014
d925970
2.4.2
dougwilson Aug 4, 2014
9824742
Fix pool.query to use typeCast configuration
dougwilson Aug 24, 2014
46481a4
2.4.3
dougwilson Aug 25, 2014
5f66ebd
Add enqueue event to protocol and connection
dougwilson Jul 14, 2014
b37beae
Blacklist unsupported connection flags
dougwilson Jul 28, 2014
fc90c7d
docs: update badges
dougwilson Sep 7, 2014
c6bd796
Make only column names enumerable in RowDataPacket
dougwilson Sep 7, 2014
f815167
Support Node.js 0.6
dougwilson Sep 7, 2014
af76081
deps: [email protected]
dougwilson Sep 7, 2014
911d2a8
deps: [email protected]
dougwilson Sep 7, 2014
97fb2f9
Remove underscore from devDependencies
dougwilson Sep 7, 2014
47fd30c
Add code POOL_ENQUEUELIMIT to error reaching queueLimit
dougwilson Sep 7, 2014
37a07b3
Add enqueue event to pool
dougwilson Sep 7, 2014
4519edb
docs: move connection event location
dougwilson Sep 7, 2014
eb204e0
2.5.0
dougwilson Sep 7, 2014
1f6393a
docs: add pool.end() documentation
Sep 16, 2014
3b131c3
Fix pool.end race conditions
dougwilson Sep 22, 2014
446735d
Fix pool.getConnection race conditions
dougwilson Sep 22, 2014
977ccfc
2.5.1
dougwilson Sep 22, 2014
bfeb3a4
test: store the value in large packet test
dougwilson Oct 11, 2014
79c733d
Fix receiving large text fields
dougwilson Jul 28, 2014
7d46d1b
2.5.2
dougwilson Oct 11, 2014
917d41a
Fix pool.query not emitting connection errors
dougwilson Nov 6, 2014
07a8abe
2.5.3
dougwilson Nov 6, 2014
83a0cc2
tests: add PoolConnection.pause/resume tests
dougwilson Nov 22, 2014
5bad10f
docs: use non-unit default value for timeouts
dougwilson Nov 30, 2014
befe3cc
Fix various error code strings
dougwilson Dec 17, 2014
b3111b8
Fix error if falsy error thrown in callback handler
dougwilson Dec 17, 2014
21d0c22
docs: fix objectMode documentation
dougwilson Dec 17, 2014
ec4a52a
deps: [email protected]
dougwilson Dec 17, 2014
c95ca93
2.5.4
dougwilson Dec 17, 2014
7ec0143
docs: add connection.ping to readme
dougwilson Dec 26, 2014
89adcba
deps: require-all@~1.0.0
dougwilson Jan 2, 2015
4b29195
deps: [email protected]
dougwilson Jan 2, 2015
3d2c76b
docs: use shields.io for node.js version badge
dougwilson Feb 11, 2015
9a0f8fd
build: use Travis CI container infrastructure
dougwilson Feb 11, 2015
c3b9b18
Support Node.js 0.12
dougwilson Feb 11, 2015
75d411b
docs: add note about mysql.escape()
alsotang Feb 1, 2015
000786e
docs: add additional information on object escape behavior
dougwilson Feb 12, 2015
20ff459
Store SSL presets in JS instead of JSON
dougwilson Feb 16, 2015
3f0057f
tests: improve fragility of timezone test
dougwilson Feb 16, 2015
09feeb0
tests: use environment for connections on CI
dougwilson Feb 16, 2015
616521c
tests: remove dead code from test
dougwilson Feb 16, 2015
09d9a85
tests: skip large field tests if necessary
dougwilson Feb 16, 2015
b41a38a
docs: update badges
dougwilson Feb 16, 2015
3fc4bbe
docs: add table of contents
jobrios Oct 22, 2014
fc85b19
build: add AppVeyor
dougwilson Feb 16, 2015
f5752a0
Update Amazon RDS certificates
dougwilson Feb 24, 2015
5e63638
2.5.5
dougwilson Feb 24, 2015
ff37b3e
docs: fix wording for true/false conversions
alsotang Feb 25, 2015
6df3bae
deps: [email protected]
dougwilson Mar 6, 2015
b8176fc
docs: add note about pausing results too long
dougwilson Mar 8, 2015
adaa340
Add poolCluster.remove to remove pools from the cluster
mlshvdv Feb 21, 2015
405c192
Improve speed formatting SQL
jonapgar Feb 27, 2015
d99fbf9
Break apart PoolCluster into one class per file
dougwilson Mar 9, 2015
91b7676
docs: list the main .query() argument signatures
dougwilson Mar 9, 2015
4fb3755
Support io.js
dougwilson Mar 10, 2015
d6dcc8b
docs: adjust multipleStatements option description
LinusU Mar 20, 2015
9f5b12b
build: [email protected]
dougwilson Mar 21, 2015
871d1d4
Make PoolCluster maps plain objects
dougwilson Mar 22, 2015
24ab607
Add optional callback to poolCluster.end
dougwilson Mar 22, 2015
c31a014
Fix un-catchable error from PoolCluster when MySQL server offline
dougwilson Mar 22, 2015
d91a62a
build: clean up .gitignore
dougwilson Mar 22, 2015
0c8f0b1
build: remove .npmignore file
dougwilson Mar 22, 2015
93889ac
deps: [email protected]
dougwilson Mar 22, 2015
3bf31da
Fix poolCluster.add to throw if PoolCluster has been closed
dougwilson Mar 22, 2015
c538d35
Fix poolCluster.add to throw if id already defined
dougwilson Mar 22, 2015
d99e162
Fix un-catchable error from poolCluster.remove
dougwilson Mar 22, 2015
40c36c7
Remove unnecessary _serviceableNodeIds from PoolCluster
dougwilson Mar 22, 2015
e9e4cb6
Add restoreNodeTimeout option to PoolCluster
dougwilson Mar 23, 2015
fc84e9e
Fix LOAD DATA INFILE handling in multiple statements
dougwilson Mar 25, 2015
312a8f6
2.6.0
dougwilson Mar 25, 2015
ad11fef
deps: [email protected]
dougwilson Mar 27, 2015
07a178f
Update bignumber.js to 2.0.5
dougwilson Mar 27, 2015
d79019b
2.6.1
dougwilson Mar 27, 2015
192c23a
Update bignumber.js to 2.0.7
dougwilson Apr 3, 2015
9559d80
docs: fix typos in readme
Apr 2, 2015
d5b9b87
Fix Connection.createQuery for no SQL
dougwilson Apr 14, 2015
92b13b5
docs: fix duplicate word
Apr 8, 2015
6eb389a
docs: add additional .query() documentation
Apr 7, 2015
fe3cd2f
tests: add some query end event tests
dougwilson Apr 15, 2015
c7ee866
2.6.2
dougwilson Apr 15, 2015
ce30611
build: [email protected]
dougwilson Apr 30, 2015
e31bbdc
docs: fix typo in readme
adrianblynch Apr 23, 2015
656b3c9
docs: fix typo in readme
roccivic Apr 22, 2015
bf3cf95
Delay implied connect until after .query argument validation
dougwilson May 1, 2015
d76cfd8
Lazy-load modules from many entry point; reduced memory use
dougwilson May 1, 2015
32c2614
Error early if callback argument to .query is not a function
dougwilson May 1, 2015
84d34ab
Do not remove connections with non-fatal errors from the pool
dougwilson May 4, 2015
5c176d5
docs: add note on binary character set type casting
dougwilson May 4, 2015
38db266
Destroy/end connections removed from the pool on error
dougwilson May 4, 2015
16b460e
2.7.0
dougwilson May 5, 2015
95bee5d
release pool connection restores pool user configuration
seangarner May 30, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/PoolConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,44 @@ PoolConnection.prototype.changeUser = function changeUser(options, callback) {
return __changeUser.apply(this, arguments);
};

PoolConnection.prototype.restoreUser = function restoreUser(callback) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire routine needs to be moved into the Pool. This is because restoring a user is a pool operation, not a connection operation. A user calling conn.restoreUser() doesn't make any sense.

var poolConfig = this._pool.config.connectionConfig;

var connection = this;
var config = connection.config;
var user = poolConfig.user;
var database = poolConfig.database;
var password = poolConfig.password;

// only when credentials have been changed from the pool defaults
if (config.user !== user || config.database !== database || config.password !== password) {
connection.changeUser({ user: user, database: database, password: password }, function (err) {
if (err) return callback(err);
// emit as if it were a new connection so consumers can setup session state again
connection._pool.emit('connection', connection);
callback(null);
});
connection._purge = false;
} else {
callback();
}
}

PoolConnection.prototype.release = function release() {
var pool = this._pool;
var connection = this;

if (!pool || pool._closed) {
return;
}

if (this._purge) {
return this.restoreUser(function (err) {
if (err) return connection.destroy();
pool.releaseConnection(connection);
});
}

return pool.releaseConnection(this);
};

Expand Down
16 changes: 14 additions & 2 deletions test/unit/pool/test-change-user-eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ var pool = common.createPool({
var closed = 0;
var server = common.createFakeServer();
var thread = 0;
var connections = 0;

server.listen(common.fakeServerPort, function(err) {
assert.ifError(err);

pool.on('connection', function(conn) {
connections++;
});

var conn0;
pool.getConnection(function(err, conn) {
assert.ifError(err);
assert.strictEqual(conn.threadId, 1);
assert.strictEqual(connections, 1);
conn0 = conn;
});

pool.getConnection(function(err, conn) {
assert.ifError(err);
assert.strictEqual(conn.threadId, 2);
assert.strictEqual(connections, 2);

conn.changeUser({user: 'user_2'}, function(err) {
assert.ifError(err);
assert.strictEqual(connections, 2);
assert.strictEqual(conn.threadId, 2);
conn.release();
conn0.release();
Expand All @@ -34,17 +42,21 @@ server.listen(common.fakeServerPort, function(err) {

pool.getConnection(function(err, conn1) {
assert.ifError(err);
assert.strictEqual(connections, 2);
assert.strictEqual(conn1.threadId, 1);
assert.strictEqual(conn1.config.user, 'user_1');

pool.getConnection(function(err, conn2) {
assert.ifError(err);
assert.strictEqual(conn2.threadId, 3);
assert.strictEqual(connections, 3);
assert.strictEqual(conn1.config.user, 'user_1');
assert.strictEqual(conn2.threadId, 2);
conn1.release();
conn2.release();

pool.end(function(err) {
assert.ifError(err);
assert.strictEqual(closed, 3);
assert.strictEqual(closed, 2);
server.destroy();
});
});
Expand Down