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

Conversation

seangarner
Copy link
Contributor

Discussed potential for this in #833 whereby a connection that is checked out from the pool then has changeUser called it would be marked for purging when it was released. Instead during release changeUser is called again to restore it back to the pool configuration before it's released back into the pool.

I've updated the test that covered restoreUser and all tests are passing locally, but I couldn't find a jshint or styleguide so I'm fully open to changes before merging.

restore a connections credentials before being returned to the pool if the connection had changeUser called on it
@dougwilson
Copy link
Member

Great! This is almost complete. It still needs to make sure that session state added in pool.on('connection', fn) is set back up as well in the restore user routine.

@seangarner
Copy link
Contributor Author

Assuming I understood correctly that's done. However a Connections emit 3 types of event, error, drain and end. Is emitting connection with the same connection multiple times safe? A consumer might be listening to those events therefore they'd end up getting multiple callbacks fire for 1 event.

I guess I could clear those listeners in restoreUser but wanted to get your thoughts on it.

@dougwilson
Copy link
Member

I'm not sure. The essence is that if a user does this:

pool.on('connection', function(conn) {
  conn.query('SET time_zone = "+00:00"')
})

That session state must be done on any connection that comes from pool.getConnection. conn.changeUser resets the connection, and would destroy that, which is why after restoring the user, those routines will need to be re-run on the connection.

@seangarner
Copy link
Contributor Author

The PR now covers that scenario, but I notice that the tests are failing with node 0.8. I'll try to pick this up over the weekend as it's getting late here.

An alternative would be to have a resetConnection event on the pool which a consumer could listen on to achieve the same thing, but with possibly clearer intent.

@dougwilson
Copy link
Member

An alternative would be to have a resetConnection event on the pool which a consumer could listen on to achieve the same thing, but with possibly clearer intent.

Yes, but that wouldn't be backwards-compatible and would delay this until whenever 3.0 came around :) To land in 2.x, it has to work with existing 2.x code :)

@dougwilson
Copy link
Member

The PR now covers that scenario, but I notice that the tests are failing with node 0.8.

It's possible it just happened to fail on 0.8 because the modifications to the test just introduced some kind of race condition, rather than it not being compatible. You may need to look closer at possible race conditions in the test.

@seangarner
Copy link
Contributor Author

Point well made ;) I'll investigate the tests then check to see if the readme needs modifying then get back to you.

@@ -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.

maybe node 0.8 emits after nextTick whereas 0.10 is calling emit immediately
@seangarner
Copy link
Contributor Author

Yo @dougwilson I think this may be ready now. I moved the method onto Pool as request, fixed the test (looked to me like emit calling listeners happens async in 0.8 - best guess without looking) and update the readme and changes.

@dougwilson
Copy link
Member

@seangarner thanks for the ping :) It looks great. I will likely have it merged tomorrow some time :D

@dougwilson dougwilson self-assigned this Jun 1, 2014
@dougwilson dougwilson added this to the 2.4 milestone Jun 1, 2014
@dougwilson dougwilson modified the milestones: 2.4, 2.5 Jul 14, 2014
@dougwilson dougwilson removed this from the 2.5 milestone Sep 7, 2014
@dougwilson dougwilson force-pushed the master branch 3 times, most recently from 17209da to 76de66e Compare September 22, 2014 19:00
@seangarner seangarner closed this May 12, 2015
@seangarner seangarner deleted the change-user-on-pool-connection-release branch May 12, 2015 06:21
@seangarner
Copy link
Contributor Author

superseded by #1088.

/me makes a note to himself to find out how the rebase went so wrong

@mysqljs mysqljs locked and limited conversation to collaborators Jul 2, 2015
dougwilson pushed a commit that referenced this pull request Jul 10, 2015
dougwilson pushed a commit that referenced this pull request Jul 10, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

10 participants